I made a script so when you touch on a part then it opens a frame. It works the first time but the second time does not work? There is no errors
local player = game:GetService("Players").PlayerAdded:Wait()
db = true
script.Parent.Touched:Connect(function()
if db == true then
player.PlayerGui.Side.TeleportFrame.Visible = true
db = false
wait(1)
db = true
end
end)
Assuming it is a server script here is the fixed version:
.Touched will return the part that touched it
local Players = game:GetService("Players")
local Debounce = false
script.Parent.Touched:Connect(function(Hit)
local Player = Players:FindFirstChild(Hit.Parent.Name)
if not Player then return end
if Debounce then
return
else
task.delay(1, function()
Debounce = false
end)
end
local PlayerGui = Player.PlayerGui
PlayerGui.Side.TeleportFrame.Visible = true
end)
If this doesnt work let me know, not used .Touched in a while
Your closing the frame on the client, and opening it on the server.
I can recommend 3 things:
.Touched on the client instead
Fire a remote to the player who touched it to open the frame
Fire a remote to the server to close the frame
Not to mention game:GetService("Players").PlayerAdded:Wait() is just gonna give you the first player it detects on playeradded so for any other players it will not work, the script i give you will work for multiple players.