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
local Players = game:GetService("Players")

function onPlayerAdded(player)
     local plr = game:GetService([[Players]]).LocalPlayer   
    local Character = plr.Character
    local Humanoid = Character:FindFirstChild('Humanoid')
    if Humanoid then
        local BDS = Humanoid:FindFirstChild('BodyDepthScale')
        local BHS = Humanoid:FindFirstChild('BodyWidthScale')
        if BDS and BHS then
            BDS.Value = .001
            BHS.Value = .001
            print("Hey boo")
        end

    end
end

--When a player joins, call the onPlayerAdded function
Players.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.

game.Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        -- Code
    end)
end)

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.

local Players = game:GetService("Players")

function onPlayerAdded(player) 
    local Character = player.Character or player.ChildAdded:Wait()
    local Humanoid = Character:FindFirstChild('Humanoid')
    if Humanoid then
        local BDS = Humanoid:FindFirstChild('BodyDepthScale')
        local BHS = Humanoid:FindFirstChild('BodyWidthScale')
        if BDS and BHS then
            BDS.Value = .001
            BHS.Value = .001
            print("Hey boo")
        end

    end
end

--When a player joins, call the onPlayerAdded function
Players.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