I made a script where if a key hits a certain part of the door, the door will open. But I also want it to trigger a RemoteEvent from the server to the client opening the door.
But there is an error that I don't quite understand how to fix: "FireClient: player argument must be a Player object"
local TweenService = game:GetService("TweenService")
local tweeninfo = TweenInfo.new(2.5, Enum.EasingStyle.Quad,Enum.EasingDirection.InOut)
local hinge = script.Parent.Hinge
local CF = Instance.new("CFrameValue")
CF.Value = hinge.CFrame
CF.Changed:Connect(function()
hinge.CFrame = CF.Value
end)
local cframeinfo1 = {Value = hinge.CFrame * CFrame.Angles(math.rad(0),math.rad(-75),math.rad(0))}
local cframeinfo2 = {Value = hinge.CFrame * CFrame.Angles(math.rad(0),math.rad(0),math.rad(0))}
local readytoOpen = true
local door = false
function onTouch(hit)
local key = hit:FindFirstChild("Key")
if key and readytoOpen then
if door == false then
TweenService:Create(CF, tweeninfo, cframeinfo1):play()
readytoOpen = false
door = true
game.ReplicatedStorage.RemoteEvent:FireClient(hit) -- Error is here
wait(2.5)
readytoOpen = true
elseif door == true then
TweenService:Create(CF, tweeninfo, cframeinfo2):play()
readytoOpen = false
door = false
game.ReplicatedStorage.RemoteEvent:FireClient(hit)
wait(2.5)
readytoOpen = true
end
end
end
script.Parent.Access.Touched:Connect(onTouch)
