Proximity prompt animation script not working

I want to be able to make a proximity prompt that freezes the player then plays an animation while the player is frozen, I started with a simple script that I found in the forums but it doesn’t work.

robloxapp-20211128-1307568.wmv (1.5 MB)

--// Varibles 
local proximityPrompt = script.Parent
local ProximityPromptService = game:GetService("ProximityPromptService")

proximityPrompt.Triggered:Connect(function(player)
	
	local controls = require(game:GetService("Players").LocalPlayer.PlayerScripts.PlayerModule):GetControls()
	
	controls:Disable()
	
wait(10)
	
	controls:Enable()
	
end)
1 Like

Is this a script or local script?

1 Like

this is a script sorry i couldn’t get back to your fast enough

Do you know what the problem is??

Sorry I went to do something and forgot about this.

You can only access controls from a local script. So you’ll have to put the code in a local script instead

Will the proximity prompt work in a local script tho?

To make the proximity prompt work while also having it in a local script would be to take use of a RemoteEvent.
edit: Simple explanation: promiximity promt triggered fire remote event. In the other script: RemoteEvent fired Connect function (ur local controls = require thing) end
Hope this helps.

1 Like
--This is a LocalScript that should be placed in StarterPlayer.StarterPlayerScripts:

--Services
local Players = game:GetService("Players")

--path to your proximity prompt
local proximityPrompt = workspace.Part.ProximityPrompt 
--your animation object path
local Animation = script.Animation 

function getHumanoid(plr)
	local char = plr.Character 
	if not char then return nil end
	return char:FindFirstChildWhichIsA("Humanoid")
end

proximityPrompt.Triggered:Connect(function(player)
	local controls = require(player.PlayerScripts.PlayerModule):GetControls()
	local humanoid = getHumanoid(player) 
	if not humanoid then return end 
	local Anim = humanoid:LoadAnimation(Animation)
	controls:Disable()
	Anim:Play()
	task.wait(10)
	controls:Enable()
	Anim:Stop()
end)
3 Likes
local prompt = script.Parent

prompt.Triggered:Connect(function(plr)
	local plrScripts = plr:WaitForChild("PlayerScripts")
	local plrModule = plrScripts:WaitForChild("PlayerModule")
	local controlModule = require(plrModule)
	local plrControls = controlModule:GetControls()
	plrControls:Disable()
	task.wait(10)
	plrControls:Enable()
end)

Needs to be a server script inside the ProximityPrompt instance itself.

The Triggered event of a prompt will only ever fire within a server script, “game.Players.LocalPlayer” is undefined in server scripts (and you already have the player object from the client which triggered the prompt anyway). I’ve made some other slight adjustments to the code such as replacing wait() with task.wait() and waiting for instances to load before creating references to them.

1 Like