Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Something is wrong with my TeamChange gui..?

Alright, so I am trying to make a teamchange gui, that checks to see if a Player is Inside of a certain group, and is within a certain rank, and it is not letting me do the Rank portion if it.

Ive used the same method in Holo commands but it just doesn't work with the gui, any and all help is appreciated.

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)
plr.Character.Humanoid:TakeDamage(100)
end
end

script.Parent.MouseButton1Click:connect(Click)


2 comments

1

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'.

0

It still does not work,

2 answers

✓ 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.

1 comment

0

Forgot to remove the Humanoid portion on line 15... Make sure that edit is made, otherwise the script will still error.

Do not use _,v to call a table, because it's only used alongside the :GetChildren() statement. Instead, use a for i=1 do statement which loops through the table.

Here is your revised script:

local gid = 2718723 
local gidranks = {255}
function contains(list, element)
    for i=1, #list do
        if list[i] == 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)
plr.Character.Humanoid:TakeDamage(100)
end
end

script.Parent.MouseButton1Click:connect(Click)

2 comments

0

Very informative but the Gui still does not work.

0

Actually, you can use for i,v in pairs() on a table or dictionary. It really doesn't matter and it should go by preference of the end user. The table will just be read like this "1 = 255". You would never use the for i=1,#list on a dictionary (table of objects and values with a string or other means of defining an index).

This discussion is preserved as it was. New answers, comments, and votes are closed.