bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
For some reason, the script doesn't work. It doesn't show an error in output, so I'm not sure what's wrong. |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Whoops, here's the script:
local debounce = false
function getPlayer(humanoid)
local players = game.Players:children()
for i = 1, #players do
if players[i].Character.Humanoid == humanoid then return players[i] end
end
return nil
end
function onTouch(part)
local human = part.Parent:findFirstChild("Humanoid")
if (human ~= nil) and debounce == false then
debounce = true
local player = getPlayer(human)
if (player == nil) then return end
person = human.Parent.Name
player = game.Players:findFirstChild(person)
points = player.leaderstats.Points.Value
end
if points >= 2 then
script.Parent:clone().Parent = player.Backpack
player.leaderstats.Points.Value = points - 2
wait(3)
debounce = false
end
end
script.Parent.Parent.Touched:connect(onTouch)
|
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
It sounds quite a bit like a logic error.
Maybe you can go to Let's Make a Deal to find a working one? |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Ever since I started to learn to script I sort of vowed to never use free models or stuff from other people unless I COMPLETELY can't do something.
I'd like to try to fix the one that I made. |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Good boy, no free models. *pats on head*
I pretty much rewrote yours.
local Cost = 2
local debounce = false
script.Parent.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player)
debounce = true
points = player.leaderstats.Points.Value
if (points >= Cost) then
player.leaderstats.Points.Value = points - Cost
script.Parent:Clone().Parent = player.Backpack
end
wait(3)
debounce = false
end
end)
|
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Woops! Coding in C# has messed up my Lua. Here.
ocal Cost = 2
local debounce = false
script.Parent.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
debounce = true
points = player.leaderstats.Points.Value
if (points >= Cost) then
player.leaderstats.Points.Value = points - Cost
script.Parent:Clone().Parent = player.Backpack
end
wait(3)
debounce = false
end
end
end) |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Might I try one more time? Sorry for posting 3 times in a row.
This one should work, it might need a tad bit of tweaking though.
local Cost = 2
local debounce = false
script.Parent.Parent.Touched:connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
debounce = true
points = player.leaderstats.Points.Value
if (points >= Cost) then
player.leaderstats.Points.Value = points - Cost
script.Parent:Clone().Parent = player.Backpack
end
wait(3)
debounce = false
end
end
end) |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
I must thouroughly read and understand it before I use it... |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
It's pretty easy to understand.
I'm just changing the way the connection works, and using :GetPlayerFromCharacter instead of searching based on the character's name.
I also made your point subtraction and stuff based on a variable.
So really, it isn't all that different. |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Oh, ok. Now I just need to fix it up a bit. |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Yeah, I was too lazy to open up studio and try and make it work on my own.
Good luck! |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Grr... I can't figure out how to solve an error message I got. It says "21: ')' expected (to close '(' at line 4) near 'end'" |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Add a ) at the end of the script.
I think you forgot to copy the ). |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Nope, still the same error message. |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Try adding another until you get a different error. |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
After adding about 25 extra )'s and getting the same message every time, I dont think thats the solution. |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Okay, in that case, I'll go ahead and actually test it. |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Thank you. I wonder what was wrong... |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Couldn't really find it.
Looks like we'll just settle for a non-anonymous function.
local Cost = 2
local debounce = false
function onTouch(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if (player) then
debounce = true
points = player.leaderstats.Points.Value
if (points >= Cost) then
player.leaderstats.Points.Value = points - Cost
script.Parent:Clone().Parent = player.Backpack
end
wait(3)
debounce = false
end
end
script.Parent.Parent.Touched:connect(onTouch) |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
When I first saw the script I thought the function part looked kinda wierd. |
|
LPGhatguyForum ModeratorJoin Date: 2008-06-27 Post Count: 4725 |
Yeah, that's simply a way to do connections when you aren't going to call the function seperate from the event. |
|
bigpekingJoin Date: 2008-05-17 Post Count: 1023 |
Well, it works now, and I'm happeh. |
|