I'm trying to make a script that runs when the specified part is touched and it tells you what difficulty you're in by a GUI coming from the top of the screen but when I test it, I touch the part and then nothing happens. The output doesn't even show a error and I think it's because where the script is placed or something but I don't know the right place for this to work.
local diffReminder = script.Parent:WaitForChild("DifficultyReminder") local hard = diffReminder.Hard local med = diffReminder.Medium local ez = diffReminder.Easy local debounce = true local stage = game.Workspace.Stages["2"] stage.Touched:Connect(function(plr) if plr:FindFirstChild("Humanoid") then if plr.leaderstats.Stage.Value >2 then debounce = false ez:Destroy() elseif plr.leaderstats.Stage.Value <2 then ez:TweenPosition( UDim2.new(0.1, 0,0.93, 0), "Out", "Back", 0.25, false ) wait(4) ez:TweenPosition( UDim2.new(0.1, 0,-1.93, 0), "In", "Back", 0.25, false ) end end end)
SCRIPT PARENT:
It's a Local Script Inside of StarterGui
If you're trying to get a touch event with a local script, you need to put it in starterplayerscripts and reference the part.
Example:
local part = workspace:FindFirstChild("examplepart") part.Touched:Connect(function(plr)
First thing, don't use a LocalScript for detecting touch and putting it in StarterGui. I would recommend you the simplest method:
-- ServerScript [Put it in the Part] local debounce = true local stage = script.Parent stage.Touched:Connect(function(plr) -- Here plr is not the player, but the part that touched print("Touch Detected!") if debounce == false then return -- Tell the function not to execute further else debounce = false -- Puts debounce to false local player = game.Players:GetPlayerFromCharacter(plr.Parent) -- It will help you to get the player local PlayerGui = player:WaitForChild("PlayerGui") -- It will access the PlayerGui [The contents of StartGui gets copied here] local diffReminder = PlayerGui:WaitForChild("DifficultyReminder") -- Change the location to your stuff local hard = diffReminder.Hard local med = diffReminder.Medium local ez = diffReminder.Easy if plr:FindFirstChild("Humanoid") then if player:WaitForChild("leaderstats").Stage.Value >2 then debounce = false ez:Destroy() elseif player:WaitForChild("leaderstats").Stage.Value <2 then ez:TweenPosition( UDim2.new(0.1, 0,0.93, 0), "Out", "Back", 0.25, false ) wait(4) ez:TweenPosition( UDim2.new(0.1, 0,-1.93, 0), "In", "Back", 0.25, false ) end end wait(3) -- Change the time according to your choice debounce = true end) -- Make sure to add full working debounce and not just the boolean value
Lemme know if it helps!