Hello!
I’m trying to make a door that can be opened by clicking a lever.
I have 2 scripts inside my clickdetector

but only the server script works.
I’ve tried looking for answers on google, but nothing.
This is the localscript:
script.Parent.MouseClick:Connect(function()
local plr = game.Players.LocalPlayer
local char = plr.Character
print("clicked")
char.HumanoidRootPart.CFrame = script.Parent.Parent.Parent.tp.CFrame
print("tpd")
local plranim = char.Humanoid:LoadAnimation(char.LeverDoorOpen)
plranim:Play()
print("anim played")
end)
and this is the server script:
script.Parent.MouseClick:Connect(function()
wait(1.433)
game.TweenService:Create(script.Parent.Parent, TweenInfo.new(0.4, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Position = Vector3.new(53.026, 3.561, 19.515)}):Play()
wait(3)
game.TweenService:Create(script.Parent.Parent, TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Position = Vector3.new(53.026, 4.56, 19.515)}):Play()
end)
There aren’t any errors in the output either.
Of course, LocalScript
don’t work on parts. I suggest putting the LocalScript
on StarterPlayerScript
and making a BindableEvent
or RemoteEvent
to communicate between ServerScript
and LocalScript
.
Local Scripts don’t run in workspace, if that’s where your ClickDetector is.
Yeah my local script is in workspace. Sorry, I didn’t know that. Thank you!
1 Like
Alright! I’ll try that. Thanks!
For this you’ll need a RemoteEvent not a BindableEvent. RemoteEvents facilitate the communication between server scripts & local scripts & vice versa, whereas BindableEvents are used to allow for communication to occur between server scripts exclusively, in your case you have a local script & a server script which need to work in tandem.
1 Like
Also, no one else has mentioned but “game.Players.LocalPlayer” is undefined in server scripts, in other words it doesn’t fetch the local player object.
I put the game.Players.LocalPlayer in the local script. Not the server script
– SERVER SCRIPT –
local replStorage = game:GetService("ReplicatedStorage")
local partClickRemote = replStorage:WaitForChild("partClickRemote")
script.Parent.MouseClick:Connect(function(player)
local character = player:WaitForChild("Character")
character.HumanoidRootPart.CFrame = script.Parent.Parent.Parent.tp.CFrame
local humanoid = character:WaitForChild("Humanoid")
local plranim = humanoid:LoadAnimation(character.LeverDoorOpen)
plranim:Play()
partClickRemote:FireClient(player)
end)
– LOCAL SCRIPT –
local replStorage = game:GetService("ReplicatedStorage")
local partClickRemote = replStorage:WaitForChild("partClickRemote")
partClickRemote.OnClientEvent:Connect(function(player)
wait(1.433)
game.TweenService:Create(script.Parent.Parent, TweenInfo.new(0.4, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Position = Vector3.new(53.026, 3.561, 19.515)}):Play()
wait(3)
game.TweenService:Create(script.Parent.Parent, TweenInfo.new(2, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {Position = Vector3.new(53.026, 4.56, 19.515)}):Play()
end)
Alright. Thank you for helping me out!

The local script will need to be moved for your use but this is how everything is organised.
1 Like
Alright. I understand now. I’m pretty new to scripting so this remote event thingy got me really confused at first. But now I understand it. Thanks!