I'm not sure why this local variable has an error on it i assigned it a value so whats the problem?
01 | script.Parent.Touched:Connect( function (hit) |
02 | local player = game.Players:GetPlayerFromCharacter |
03 | local Money = player.leaderstats.Money -- my question,I just want to know whats causing the "local" error it says expected '(' and <string> what does it mean |
04 |
05 | if hit.Parent = = game.Workspace.PartStorage then |
06 | wait( 0.4 ) |
07 | Money.Value = Money.Value + hit.Value |
08 | hit:Destroy() |
09 |
10 |
11 | end |
12 |
13 | end |
14 |
15 |
16 |
17 |
18 | end ) |
You are not using GetPlayerFromCharacter correctly. It is a function and you need to call it passing it the instance to attempt to find the player. If no player is found then nil is returned.
1 | script.Parent.Touched:Connect( function (hit) |
2 | local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- hit.Parent would be the model |
3 | if player then -- check that player is not nil |
4 | -- code |
5 | end |
6 | end ) |
I hope this helps. Please comment if you have any other questions about this code.
This should work. You aren't getting the player correctly and for that reason you can't get the leaderstats.
1 | local user = game.Players:GetPlayerFromCharacter(hit.Parent) |
2 | local stats = user:findFirstChild( "leaderstats" ) |
3 |
4 | if stats ~ = nil then |
5 | local cash = stats:findFirstChild( "Money" ) |
6 | cash.Value = cash.Value + numbervalue |