I'm making a game where if you click on the text button, it would set you to a specific size. it does work, but all players on the server are made that size, rather than just the player. after looking through the code, I found out that this line of code is the reason why it does everyone.
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
how do I fix this so that way the player who clicks that button is set to that size?
EDIT: it might be easier to help if i put the entire script.
local Enabled = false
script.Parent.MouseButton1Click:Connect(function()
if not Enabled then
Enabled = true
function PlayerSize(player)
local SizeValue = 25
local humanoid = player.Character.Humanoid
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale") then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthScale") then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale") then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale") then
humanoid.HeadScale.Value = SizeValue
end
end
end
wait(2)
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
end
else
Enabled = false
function PlayerSize(player)
local SizeValue = 25
local humanoid = player.Character.Humanoid
if humanoid then
if humanoid:FindFirstChild("BodyHeightScale") then
humanoid.BodyHeightScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyWidthScale") then
humanoid.BodyWidthScale.Value = SizeValue
end
if humanoid:FindFirstChild("BodyDepthScale") then
humanoid.BodyDepthScale.Value = SizeValue
end
if humanoid:FindFirstChild("HeadScale") then
humanoid.HeadScale.Value = SizeValue
end
end
end
wait(2)
for i, player in pairs(game.Players:GetPlayers()) do
PlayerSize(player)
end
end
end)

3 comments
ClickDetector's pass the Player who interreacted with the Instance to your Callback as an Argument, use it as a Parameter instead of Iterating over every Player in-game.
Is this in a local script?
You should use LocalScript to get the player instead.