Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I made a team change gui but the script only works in studio please help thank you. ?

Asked by 9 years ago

I made a gui with a textbutton that is supposed to switch teams and have different text based off of what team you're on but it only works in studio and I don't know any better way to do what I'm trying to do.

Link to place:(http://www.roblox.com/games/336021906/ScriptBox)

Script:

--By MrDefaultMan

--Declaring Variables
local team1 = game.Teams.Hub
local team2 = game.Teams.Training
dud = game.Players.LocalPlayer
local green = Color3.new(0, 170, 0)
huh = dud.Character:FindFirstChild('Humanoid')

if dud.TeamColor == BrickColor.new('Medium stone grey') then  --if ur in Training the text is "back to hub"
    script.Parent.Text = "back to hub"
end
if dud.TeamColor == BrickColor.new('Ghost grey') then  --if ur in Hub the text is "to training"
    script.Parent.Text = "to training"
end

script.Parent.MouseButton1Down:connect(function(click)  --Changes teams
    if script.Parent.Text == "back to hub" then
        huh.Health = 0
        dud.TeamColor = BrickColor.new('Ghost grey')
    end
    if script.Parent.Text == "to training" then
        huh.Health = 0
        dud.TeamColor = BrickColor.new('Medium stone grey')
    end
end)
0
Oh the green variable has something to do with another gui that should not be in the script because it means nothing ignore it. MrDefaultMan 113 — 9y
0
line 8 should wait for the character; huh=(dud.Character or dud.CharacterAdded:wait()):FindFirstChild("Humanoid") 1waffle1 2908 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

Is that in a server script? The reason why it may not be working online is because you define the player as "game.Players.LocalPlayer," but that only works in a local script. Try that code in a local script and see if it works for you!

0
Idk still doesnt work ingame MrDefaultMan 113 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Try doing this,

--By MrDefaultMan

--Declaring Variables
local team1 = game.Teams.Hub
local team2 = game.Teams.Training
local dud = script.Parent.Parent.Parent.Parent.Parent
local huh = dud.Character:FindFirstChild("Humanoid")

if dud.TeamColor == BrickColor.Gray() then  --if ur in Training the text is "back to hub"
    script.Parent.Text = "back to hub"
end
if dud.TeamColor == BrickColor.new("Ghost grey") then  --if ur in Hub the text is "to training"
    script.Parent.Text = "to training"
end

script.Parent.MouseButton1Down:connect(function(click)  --Changes teams
    if script.Parent.Text == "back to hub" then
        huh.Health = 0
        dud.TeamColor = BrickColor.new("Ghost grey")
    elseif script.Parent.Text == "to training" then
        huh.Health = 0
        dud.TeamColor = BrickColor.new("Medium stone grey")
    end
end)

I tested it. I got it to work.

0
did it work ingame?, mine only works when testing in studio MrDefaultMan 113 — 9y
0
I didn't test in game. JamesLWalker 297 — 9y
Log in to vote
0
Answered by 9 years ago

I may or may not be correct, but from what I see the if then statements only will run once each. You have nothing calling them for when the players team color changes. I'm not exactly sure how to do this, as I've had issues doing this in the past.

As Vexture says, making it a LocalScript. Your script seems to be under a GUI, so game.Players.LocalPlayer wouldn't work even if it were a localscript. Keep it as a normal script. Instead, use pairs to get all the players in game.Players. Like this:

local dud;
local huh;
function dud() --Dud is all of the players in game.Players now.
    for i, v in pairs(game.Players:GetChildren()) do 
    return v
    end
end

dud = dud()
huh = dud.Humanoid

Also know that when you change something inside of a GUI, it must also change inside the PlayerGui. Example is below.

So, if I had created this script I'd probably had done this:

local team1 = game.Teams.Hub
local team2 = game.Teams.Training
local dud;
local green = Color3.new(0, 170, 0)
local huh;

function dud() --Dud is all of the players in game.Players now.
    for i, v in pairs(game.Players:GetChildren()) do 
    return v
    end
end

dud = dud()
huh = dud.Humanoid

while wait() do --Checks every few miliseconds
if dud.TeamColor == BrickColor.new('Medium stone grey') then  --if ur in Training the text is "back to hub"
    script.Parent.Text = "back to hub"
dud.PlayerGui.GuiName.Text = "back to hub"
end
end
while wait() do --Checks every few miliseconds
    if dud.TeamColor == BrickColor.new('Ghost grey') then  --if ur in Hub the text is "to training"
    script.Parent.Text = "to training"
    dud.PlayerGui.GuiName.Text = "to training"
end
end

script.Parent.MouseButton1Down:connect(function(click)  --Changes teams
    if script.Parent.Text == "back to hub" then
        dud.TeamColor = BrickColor.new('Ghost grey') --I switched around the two so that their teamcolor is changed before they respawn, even though it probably doesn't matter.
        huh.Health = 0
    end
    if script.Parent.Text == "to training" then
        dud.TeamColor = BrickColor.new('Medium stone grey')
        huh.Health = 0
    end
end)

I hope this helps! I did this quickly so if anything is incorrect, just tell me and I'll try to fix it.

Answer this question