ImageButton Team Changer not working

Hello! So i was making an textbutton for change player’s team, problem is that is not working, here’s the script witch i’ve made:

local textButton = script.Parent

local teamName = "TeamName" --sample team name.

local function changeTeam()

    local player = game.Players:GetPlayerFromCharacter(textButton.Parent)

    local team = game.Teams:FindFirstChild(teamName)

    if player and team then
        player.Team = team
    end
end


textButton.MouseButton1Click:Connect(changeTeam)

Here’s an explorer screenshot too:
Captura de pantalla 2023-09-09 a las 23.33.44
So, “jobs” is the button (imagebutton) and “script” is where it’s located the shared script from before. If someone could help me out on these, I would really apreciate it!

Thats because textButton.Parent is the ScreenGui (probably), not the player i think you need to add 2/3 more .Parent

Check the console for any errors, we need to know what the script is doing to debug it. Also @yoshicoolTV is probably right in that it won’t get the player

(I suggest using a RemoteEvent and a single script in ServerScriptService, it makes this a bit easier to do)

the player variable is better to be replaced with
local player = game.Players.LocalPlayer
that is if its a local script

Yeah! That solved the issue, thank you very much for the help, and @Claym1x & @yoshicoolTV too for the suggestions!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.