Localscript Not Work

I Think This Will Be Very Dumb Question, Am Making Script That Hide Prompt To Player That Activated Prompt For 5 Second, And For Some Reason, Script Not Work, Got No Error In Outputs.

local detector = script.Parent

detector.Triggered:Connect(function(player)
	script.Parent.Enabled = false
	task.wait(5)
	script.Parent.Enabled = true
end)

Is it a LocalScript in workspace? If so, Local Scripts don’t work in workspace, try a server script.

It seems like you putted this script inside Workspace. As @hasoco said, LocalScripts doesn’t run inside Workspace. Instead, put this LocalScript inside StarterPlayerScripts and write the following code-

local detector = workspace.Part --example

detector.Triggered:Connect(function(player)
	detector.Enabled = false
	task.wait(5)
	detector.Enabled = true
end)
1 Like

It depends on what he wants. He wants that it disables for the client who triggered it. If we use a Script, then this would be disabled for all the players, not just the player who triggered it.

Server-script:

local detectorPart = script.Parent -- Assuming this script is inside of the part
local proximityPrompt = detectorPart.ProximityPrompt -- Assuming this ProximityPrompt is inside of the part

proximityPrompt.Triggered:Connect(function(player)
	proximityPrompt.Enabled = false
	task.wait(5)
	proximityPrompt.Enabled = true
end)

:neutral_face:

Okay so the problem is that you need a remote event.

A remote event lets the server communicate with the client, which is exactly what you need in your case, since a LocalScript can’t run in the Workspace like everyone has said 2,000 times.

Okay so you’ll need 2 new scripts; A server script that can go anywhere in the Workspace (preferably a child of the prompt) that references the proximity prompt, and a local script that is parented to StarterPlayerScripts.

Then, create a RemoteEvent and place it in ReplicatedStorage. Name it visRemote.

Local script:

local remote = game.ReplicatedStorage:WaitForChild("visRemote")

remote.OnClientEvent:Connect(function(prompt)
prompt.Visible = false
end)

Server script: (assuming script is a child of proximity prompt in this case)

local remote = game.ReplicatedStorage:WaitForChild("visRemote")
local detector = script.Parent

detector.Triggered:Connect(function(player)
	remote:FireClient(player, detector)
end)

The beauty of remote events is that you can use this for as many proximity prompts as you want.

I hope this makes sense. As said before, since a prompt can’t be directly activated via a local script, a RemoteEvent is needed so the server can fire the client.

No? I’ve fired it many times although.

Did you know that local scripts don’t work in workspace? Better put ls on startergui and rescript

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.