Your fix is easy.
don't worry, it was a simple mistake.
I'll quickly run you through this.
First, It would be easier to replace the function's variable player, and simply call it hit.
Why? Because when you touch a part, The player value in your sense is the PART in your player's character, not the player.
so replace line 1 with
1 | script.Parent.Touched:connect( function (hit) |
And put a line between lines 1 and 2:
1 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
then add an if loop to see if it's not just some part.
here's the finished code.
01 | script.Parent.Touched:connect( function (hit) |
02 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | local persongui = player.PlayerGui.MoneyGui.TextLabel.Money |
08 | persongui.Value = persongui.Value + 10 |
That's All you really need. But judging you'll hit this part 2-5 times, you may want to put in a debounce.
Here's that.
03 | script.Parent.Touched:connect( function (hit) |
04 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
06 | if player and not debounce then |
08 | local persongui = player.PlayerGui.MoneyGui.TextLabel.Money |
11 | persongui.Value = persongui.Value + 10 |
BUT!
This debounce has no effect except only being able to be touched once. How to fix?
Easy.
Simply use a repeat
instead of a while
loop. This will give your 'money giver' a limited amount of time.
04 | script.Parent.Touched:connect( function (hit) |
05 | player = game.Players:GetPlayerFromCharacter(hit.Parent) |
07 | if player and not debounce then |
09 | local persongui = player.PlayerGui.MoneyGui.TextLabel.Money |
13 | persongui.Value = persongui.Value + 10 |
For example, above, this code will become untouchable, give the specified player 10C/second until the time variable = the waitTime variable. Then debounce turns off.
Here's some nice wiki pages on your subject.
http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerFromCharacter ~GetPlayerFromCharacter
http://wiki.roblox.com/index.php?title=Debounce ~Debounce
http://wiki.roblox.com/index.php?title=Loops ~Different kinds of loops
That's all I have for today. If you liked the answer, slap that upvote and accept this answer IN THE FACE!
baibai
EEDIT: None of this worked lol