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.
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.
--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)
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.