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)
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)
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)
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)