Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

Your defining a variable and not using it...... You're also using LocalPlayer in a server script...

0

He not helpful ^

2 answers

✓ Accepted answer

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.

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.

2 comments

0

There's no local player server-side. Also, this would only work once.

0

Yea I was already working on fixing this when you commented, I saw hiimgoodpack's comment on the OP

This discussion is preserved as it was. New answers, comments, and votes are closed.