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

Show gui to player not working?

Asked by 9 years ago

Hi guys This is meant to show a gui and when the player switches to the green team, but instead it shows it when they join the game and when they change to ANY team. Any ideas? Thanks

It is a local script parented to an imagelabel in screengui.

local Frame = script.Parent 
local TeamColor = BrickColor.new("Bright green") 

local Player = game.Players.LocalPlayer
local function Check()


Frame.Visible = Player.TeamColor == TeamColor
script.Parent.Visible = true
script.Parent:TweenPosition(UDim2.new(0.15, 0, 0.15, 0), "Out", "Bounce", 1)
wait(4)
script.Parent:TweenPosition(UDim2.new(0.15, 0, -0.7, 0), "Out", "Bounce", 1)
wait(2)
script.Parent.Visible = false

end Player.Changed:connect(Check)

1 answer

Log in to vote
6
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

First it should be said that you have no reason to continuously use script.Parent when you already have a variable for it.


Anyways, your problem is line 09.

On line 8, you use a rather clever way to make the frame visible or invisible based on the TeamColor, but then you just go ahead and make it visible on line 09, making line 8 useless!

You could simply take out line 9;

--Tab your code correctly!
local function Check()
    Frame.Visible = Player.TeamColor == TeamColor
    Frame:TweenPosition(UDim2.new(0.15, 0, 0.15, 0), "Out", "Bounce", 1)
    wait(4)
    Frame:TweenPosition(UDim2.new(0.15, 0, -0.7, 0), "Out", "Bounce", 1)
    wait(2)
    Frame.Visible = false
end 

But then you're tweening the GUI no matter what -- Not exactly super efficient. You could do this;

local function Check()
    if Player.TeamColor == TeamColor then
        Frame.Visible = true
        Frame:TweenPosition(UDim2.new(0.15, 0, 0.15, 0), "Out", "Bounce", 1)
        wait(4)
        Frame:TweenPosition(UDim2.new(0.15, 0, -0.7, 0), "Out", "Bounce", 1)
        wait(2)
        Frame.Visible = false
    end
end 

Or if you only want the GUI to show when they FIRST join the team, and not when they respawn or anything, you can use the built in parameter of Changed events (it's equal to the property that fired the event);

local function Check(property)
    if property == "TeamColor" and Player.TeamColor == TeamColor then
        Frame.Visible = true
        Frame:TweenPosition(UDim2.new(0.15, 0, 0.15, 0), "Out", "Bounce", 1)
        wait(4)
        Frame:TweenPosition(UDim2.new(0.15, 0, -0.7, 0), "Out", "Bounce", 1)
        wait(2)
        Frame.Visible = false
    end
end 
2
thank you very much for helping, but this doesn't work :( local function Check(property) if property == "TeamColor" and Player.TeamColor == TeamColor then Frame.Visible = true Frame:TweenPosition(UDim2.new(0.15, 0, 0.15, 0), "Out", "Bounce", 1) wait(4) Frame:TweenPosition(UDim2.new(0.15, 0, -0.7, 0), "Out", "Bounce", 1) wait(2) Frame.Visible = fa jjwood1600 215 — 9y
0
Oh, dont worry - got it working ;) thanks for your help! jjwood1600 215 — 9y
2
What exactly wasn't working? Perci1 4988 — 9y
Ad

Answer this question