Why wont this script work? Most of it does but it does not change the height leaderstat to + 1 like it should.
01 | local debounce = false |
02 | script.Parent.Touched:Connect( function (hit) |
03 | local hum = hit.Parent:FindFirstChildOfClass( "Humanoid" ) |
04 | if hum and game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) and not debounce then |
05 | debounce = true |
06 | hum.BodyHeightScale.Value = hum.BodyHeightScale.Value + 0.1 |
07 |
08 | script.Parent.Transparency = 1 |
09 | script.Parent.CanCollide = false |
10 | task.wait( 5 ) |
11 | script.Parent.Transparency = 0 |
12 | script.Parent.CanCollide = true |
13 | debounce = false |
14 |
15 | game.Players.LocalPlayer.leaderstats.Height.Value = game.Players.LocalPlayer.leaderstats.Height.Value + 1 |
16 |
17 | end |
18 | end ) |
Thanks!
You can't use LocalPlayer in a ServerScript. Also, try to avoid nesting, whenever you can.
This should work:
01 | local debounce = false |
02 | script.Parent.Touched:Connect( function (hit) |
03 | local hum = hit.Parent:FindFirstChild( "Humanoid" ) |
04 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
05 | if not hum and plr then return end |
06 | if debounce = = true then return end |
07 | debounce = true |
08 | hum.BodyHeightScale.Value + = . 1 |
09 | plr.leaderstats.Height.Value + = 1 |
10 | script.Parent.Transparency = 1 |
11 | script.Parent.CanCollide = false |
12 | task.wait( 5 ) |
13 | script.Parent.Transparency = 0 |
14 | script.Parent.CanCollide = true |
15 | debounce = false |
16 | end ) |