Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why doesnt this set my humanoid size? This Is A Server Script!

Asked by 6 years ago
Edited 6 years ago
01local Players = game:GetService("Players")
02 
03function onPlayerAdded(player)
04     local plr = game:GetService([[Players]]).LocalPlayer  
05    local Character = plr.Character
06    local Humanoid = Character:FindFirstChild('Humanoid')
07    if Humanoid then
08        local BDS = Humanoid:FindFirstChild('BodyDepthScale')
09        local BHS = Humanoid:FindFirstChild('BodyWidthScale')
10        if BDS and BHS then
11            BDS.Value = .001
12            BHS.Value = .001
13            print("Hey boo")
14        end
15 
16    end
17end
18 
19--When a player joins, call the onPlayerAdded function
20Players.PlayerAdded:connect(onPlayerAdded)
0
Your defining a variable and not using it...... You're also using LocalPlayer in a server script... hiimgoodpack 2009 — 6y
0
He not helpful ^ BlackOrange3343 2676 — 6y

2 answers

Log in to vote
3
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

There's no need to use multi-line string syntax, quotes are fine, and you already fetched the service before with a variable. The server has no concept of a local player, because the local player is the Player instance of the client.

The player's Player.Character will be nil when the character does not exist. Use the Player.CharacterAdded event to get around this.

1game.Players.PlayerAdded:Connect(function(Player)
2    Player.CharacterAdded:Connect(function(Character)
3        -- Code
4    end)
5end)

RBXScriptSignal:connect() with a lowercase c is deprecated, switch to RBXScriptSignal:Connect() with a capital C.

Ad
Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

The output window is your friend! When I run your script I get the error Script:6: attempt to index local 'Character' (a nil value) in output, so this tells us it doesn't know what "Character" is.

We can fix this by adding "or plr.CharacterAdded:Wait()" What this does is pretty simple, the first half (before the "or") tries to set the variable to the character linked with the player, but if it doesn't exist, it moves on to the second half (after the "or").

The second part, "plr.CharacterAdded:Wait()", makes the script wait until a character is added, then continues on.

01local Players = game:GetService("Players")
02 
03function onPlayerAdded(player)
04    local Character = player.Character or player.ChildAdded:Wait()
05    local Humanoid = Character:FindFirstChild('Humanoid')
06    if Humanoid then
07        local BDS = Humanoid:FindFirstChild('BodyDepthScale')
08        local BHS = Humanoid:FindFirstChild('BodyWidthScale')
09        if BDS and BHS then
10            BDS.Value = .001
11            BHS.Value = .001
12            print("Hey boo")
13        end
14 
15    end
16end
17 
18--When a player joins, call the onPlayerAdded function
19Players.PlayerAdded:connect(onPlayerAdded)

I also made 2 more changes:

First I changed line 4, not only was this variable unnecessary since the function has a "player" variable linked to it, but also you were trying to get LocalPlayer from a server script, which is not possible.

And the final thing is you were using "connect" instead of "Connect". "connect" is deprecated, which means you shouldn't use it anymore for new work.

0
There's no local player server-side. Also, this would only work once. Avigant 2374 — 6y
0
Yea I was already working on fixing this when you commented, I saw hiimgoodpack's comment on the OP User#1007 6 — 6y

Answer this question