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

The value isnt copying can anyone help?

Asked by 5 years ago

This isnt changing the size for some reason im so confused

wait(10)

function join(plr)
    lr = plr.Name
end
while true do
    wait(0.1)
    game.Players:WaitForChild(lr).Character.Humanoid.BodyHeightScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
    game.Players:WaitForChild(lr).Character.Humanoid.BodyWidthScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
    game.Players:WaitForChild(lr).Character.Humanoid.BodyDepthScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
    game.Players:WaitForChild(lr).Character.Humanoid.HeadScale.Value = game.Players:WaitForChild(lr).leaderstats.Size.Value
end


game.Players.PlayerAdded:Connect(join)
0
every time a player joins, their name overrides the previous players name theking48989987 2147 — 5y
0
so what should i do? cameronjamesg2007 7 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

The problem with your script above was that you were setting the lr value to a new player each time someone joined. It also isn't very good to have a while loop with only a tenth of a second delay. Here's what I'd recommend. You can start with the player added event which you already have.

game.Players.PlayerAdded:Connect(function()

end)

Then we can add a CharacterAdded event that fires everytime someone spawns in instead of every 0.1 seconds.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)

    end)
end)

And finally, we can add the code to modify the player's character.

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local humanoid = char:FindFirstChild("Humanoid")
        local size = plr.leaderstats.Size.Value
        if humanoid then
            humanoid.BodyHeightScale.Value = size
            humanoid.BodyWidthScale.Value = size
            humanoid.BodyDepthtScale.Value = size
            humanoid.HeadScale.Value = size
        end
    end)
end)

If you want the size to update whenever the values do then you can add a Changed event.

function updateSize(plr) -- Putting this just makes it so we don't have to write the same code twice. We can just define it in a function and call it whenever we need.
    local char = plr.Character
    if char then
        local humanoid = char:FindFirstChild("Humanoid")
        local size = plr.leaderstats.Size.Value
        if humanoid and size then
            humanoid.BodyHeightScale.Value = size
            humanoid.BodyWidthScale.Value = size
            humanoid.BodyDepthtScale.Value = size
            humanoid.HeadScale.Value = size
        end
    end
end

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        updateSize(plr)
    end)
    plr:WaitForChild("leaderstats").Size.Changed:Connect(function()
        updateSize(plr)
    end)
end)

If you have any questions I'd be happy to answer them.

0
the thing is, it's likely he wants the scale to update whenever the size updates, not just when they respawn User#22604 1 — 5y
1
My bad, I missed that. I've added it in now. Crazycat4360 115 — 5y
0
that won't work because char will be nil in the Changed scope User#22604 1 — 5y
0
Went through and refined a few things. Should work now Crazycat4360 115 — 5y
Ad

Answer this question