I try to make a part and when you touch it, a ScreenGui appears
The problem is that I had developed this thing in a test place, then I put it in my game, it didn’t work And I hadn’t touched anything (and it’s not the first time its happens to me)
You should be handling your script on the client (I mean, you don’t have to, but I suggest you to)… I’ve created a new script for you. Create a LocalScript and change it to this:
LocalScript
local Popup = script:WaitForChild("ScreenGui") -- your popup gui
local PartToTouch = game.Workspace.TestPart -- choose your part
local Player = game:GetService("Players").LocalPlayer
local Ready = true
local function onTouch(hit)
if hit.Parent:IsA("Model") then
local hitPlr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if hitPlr and hitPlr == Player then
if Ready then
Ready = false
local PlayerGui = Player:WaitForChild("PlayerGui")
local PopupClone = Popup:Clone()
PopupClone.Enabled = true
PopupClone.Parent = PlayerGui
task.wait(1)
Ready = true
end
end
end
end
PartToTouch.Touched:Connect(onTouch)
Make sure to reference the part you want touched, in the LocalScript. Also, make sure to parent/place your ScreenGui into the LocalScript, and parent/place the LocalScript into StarterPlayer > StarterPlayerScripts
In your future projects, make sure to use task.wait instead of wait.
Let me remake the code for you.
Please mark this as the Solution if this helped.
local Popup = script.ScreenGui
local Ready = true
local function onTouch(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and Ready == true then
Ready = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local c = Popup:Clone()
c.Parent = player.PlayerGui
wait(1)
Ready = true
end
end
script.Parent.Touched:Connect(onTouch)
You had a lot of errors in your code. Note: Always put local in front of a variable. So hackers can’t access it easily.
local Players = game:GetService("Players")
local Popup = script:WaitForChild("ScreenGui")
local debounce = true
function onTouch(Hit)
local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
if Humanoid and debounce then
debounce = not debounce
local Player = Players:GetPlayerFromCharacter(Humanoid.Parent)
if not Player then return end
local Clone = Popup:Clone()
Clone.Enabled = true
Clone.Parent = Player.PlayerGui
task.wait(1)
debounce = not debounce
end
end
script.Parent.Touched:Connect(onTouch)