Why is my script to change the height values if they are on a certain team roblox?

So going to my last post I have this script I was working on

local teamSizeIndex = {
    Parents = 1,
    Teens = 0.75,
    Kids = 0.5
}

game.Players.PlayerAdded:Connect(function(player)
    local function updateSize()
        wait(0.1) 
        if player.Team then 
            local char = player.Character
            local size = teamSizeIndex[player.Team.Name]
            char.Humanoid.BodyHeightScale.Value *= size
            char.Humanoid.BodyWidthScale.Value *= size
            char.Humanoid.BodyDepthScale.Value *= size
            char.Humanoid.HeadScale.Value *= size
        end
    end
    player.CharacterAdded:Connect(updateSize)
    player:GetPropertyChangedSignal("Team"):Connect(updateSize)
end)

And I wanna know why it is not working. No errors, and it is placed in serverscriptservice, but it is not working, can anybody help me find out why?

Since Team.Name is a string, shouldn’t the dictionary keys be strings?

local teamSizeIndex = {
    ["Parents"] = 1,
    ["Teens"]= 0.75,
    ["Kids"] = 0.5
}

I was told that lua is smart enough to figure out the data type by itself, so this shouldn’t be the problem.

This did not seem to work. So I am clueless

We looked at his game place and it turns out that the team was changing from a local script instead of a server script.

We ended up creating a script that changes the player’s team through a server script:

local gui = script.Parent
local player = script.Parent.Parent.Parent


for _, child in pairs(script.Parent:GetChildren())do
	local index = child.Name:find("Selection")
	
	--if the child is a team selection button:
	if index then
        --change team on button click: 
		local teamName = child.Name:sub(1, index-1)
		print(teamName)
		child.MouseButton1Click:connect(function()
			gui.Enabled = false
			player.Team = game:GetService("Teams"):FindFirstChild(teamName)
		end)
	end
end

image

It’s not about Lua being able to tell the datatype. In code similar to local x = {y = z}, z will always be saved at index “y” (y would always be a string). It’s similar to why x.y doesn’t require the quotes.

4 Likes

Thanks for explaining that, I even learned something.