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

PlayerGui only works for me, not others!?

Asked by 9 years ago

Every time i use a PlayerGui (brick onTouch) a GUI pops up for me and thats great, but then when a person touches the same button after me it doesn't work. Why is that? Please don't thumbs down, i just need to know

debounce = false

script.Parent.Touched:connect(function(hit)
    if debounce == false then
        debounce = true
local   humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.Intro.Window.Text.Visible = true
        player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,150))
        player.PlayerGui.Intro.Window.Text.Text = "Remember what i said? Red bricks are a no no. Try to avoid them as much as possible! (Hint: They kill you) ~NonSpace"
        -- first time learning Tweening!
                wait(10)
        player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,400))
        wait(1)
        player.PlayerGui.Intro.Window.Text.Visible = false

        debounce = false
        end
    end
end)
0
Have you checked for errors after having stepped on the part? Muoshuu 580 — 9y
0
yeah, no errors NonSpace 0 — 9y
0
Could you edit your post and add the code? Muoshuu 580 — 9y
0
ok NonSpace 0 — 9y

3 answers

Log in to vote
0
Answered by
Muoshuu 580 Moderation Voter
9 years ago

Your problem was the debounce, the other user would have been able to step on the part 11 seconds after you, because after that time, the debounce would have been set to false. This is because the script is not local, the debounce is set for every single user in the game. To fix this, I've made it add a 'Model' named 'Debounce' to the Player's Humanoid so that multiple people will be able to step on it at the same time.

script.Parent.Touched:conenct(function(Hit)
    local Humanoid=Hit.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        if Humanoid:FindFirstChild("Debounce") then return end
        local Debounce=Instance.new("Model",Humanoid)
        Debounce.Name="Debounce"
        local Player=game.Players:FindFirstChild(Hit.Parent.Name)
        Player.PlayerGui.Intro.Window.Text.Visible=true
        Player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,150))
        Player.PlayerGui.Intro.Window.Text.Text="Remember what I said? Red bricks are a no-no. Try to avoid them as much as possible! (Hint: They kill you) ~NonSpace"
        wait(10)
        Player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,400))
        wait(1)
        Player.PlayerGui.Intro.Window.Text.Visible=false
        Debounce:destroy()
    end
end)
0
Your Debounce model script thing doesn't work .-. NonSpace 0 — 9y
0
Any errors? Muoshuu 580 — 9y
0
nope NonSpace 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

I edited the coding a bit, you had 99% of it correct.

This should correctly work now. Make sure the GUI is in your StarterGui!

script.Parent.Touched:connect(function(hit)
local  humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        player.PlayerGui.Intro.Window.Visible = true
        player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,150))
        player.PlayerGui.Intro.Window.Text.Text = "Remember what i said? Red bricks are a no no. Try to avoid them as much as possible! (Hint: They kill you) ~NonSpace"
         wait(3)
        player.PlayerGui.Intro.Window:TweenPosition(UDim2.new(0,0,0.5,400))
        wait(1)
        player.PlayerGui.Intro.Window.Visible = false
    end
end)
0
You've removed the debounce, this will call 'Touched' multiple times... Muoshuu 580 — 9y
0
But how isn't the GUI glitching out if there is no debounce? NonSpace 0 — 9y
0
@mu, No it wont. @NonSpace, Basicly If you touch it a crud load of times the GUI will reset almost instaly due to I made Window visible=false insted of the text, Now if I had Text.Visible=false yes the GUI would glitch. MessorAdmin 598 — 9y
Log in to vote
0
Answered by 9 years ago

Please don't post duplicate questions.

You could simply use a table to check who is actively receiving this message.

I also cleaned up the code by remove the unneeded humanoid check and using the variable window.

local peoples = {}

script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player and not peoples[player.Name] then
        peoples[player.Name] = true
        local window = player.PlayerGui.Intro.Window
        window.Text.Visible = true
        window:TweenPosition(UDim2.new(0,0,0.5,150))
        window.Text.Text = "Remember what i said? Red bricks are a no no. Try to avoid them as much as possible! (Hint: They kill you) ~NonSpace"
        wait(10)
        window:TweenPosition(UDim2.new(0,0,0.5,400))
        wait(1)
        window.Text.Visible = false
        peoples[player.Name] = false --You could also remove this line if you want this to only show up once no matter how many times they touch the brick.
    end
end)

Answer this question