Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesnt localscripts work on proximity prompts?

Asked by 1 year ago

doesnt work, really strange.

script.Parent.Triggered:Connect(function()
    print("Test")
end)

nothing outputs the local script is inside of the proximity prompt, i tried using remote events but when i do OnClientEvent (yes i called it through a regular script) nothing happens again. Its really frustrating. Nothing works

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

It's important to know that LocalScripts cannot run in workspace. Instead, you need to use a regular script and RemoteEvents.

For example, in the ProximityPrompt under workspace you would use a regular script with something like this:

script.Parent.Triggered:Connect(function(plr)
    game:GetService("ReplicatedStorage"):FindFirstChild("RemoteEvent"):FireClient(plr)
end)

Note: You will need to have a RemoteEvent in ReplicatedStorage

Then in a LocalScript which I would put in StarterPlayerScripts you would write something like this:

game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").OnClientEvent:Connect(function()
    -- Whatever you want to happen
    print("ProximityPrompt triggered")
end)

Alternatively

You can just reference the proximity prompt from a LocalScript in StarterPlayerScripts (or another place where LocalScripts work)

This would look something like:

game.workspace.Part:WaitForChild("ProximityPrompt").Triggered:Connect(function()
    -- Whatever you want to happen
    print("ProximityPrompt triggered")
end)
0
Another alternative is the change RunContext of a normal script to Client and it will act like a localscript T3_MasterGamer 2189 — 1y
Ad

Answer this question