✓ Accepted answer
##Problem
First off, I would not recommend handling GUI elements with a ServerScript. I would recommend using RemoteEvents and sending a signal to the server whenever a player hits the button. However, for your case I will work with the server script. If your game has FilteringEnabled turned on, let me know so I can modify this answer. ServerScripts will not work with PlayerGui objects.
Your problem was you were changing the TeamColor to an object value on line 15. This normally would error out the script.
##Solution
Once again, if you have FilteringEnabled turned on, then that will be a completely different answer. Right now the only thing you would have to do is stick .TeamColor to the end of the Trainer teams object value you have on line 15.
##Recommendation
I would also recommend breaking a character's joints rather than relying on health to kill a user. All you have to do is use the player's character and use the method :BreakJoints() on it.
##Final Script
local gid = 2718723
local gidranks = {255}
function contains(list, element)
for _,v in pairs(list) do
if value == element then
return true
end
end
end
function Click(mouse)
local plr = script.Parent.Parent.Parent.Parent.Parent
if contains(gidranks, plr:GetRankInGroup(gid)) then
plr.TeamColor=BrickColor.new(game.Teams.Trainer.TeamColor)
plr.Character:BreakJoints()
end
end
script.Parent.MouseButton1Click:connect(Click)
######Hopefully this answered your question, if so do not forget to hit the accept answer button. If you have any questions, feel free to comment below. If it still does not work, look into output or developer console and let us know of any errors.
2 comments
You changed the name of the variable in the contains() function. It was stated as 'v' but later you tried to refer to it as 'value'.
It still does not work,