Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] Server script error when triggering RemoteEvent to client. Any help?

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)

1 answer

Never mind. I found an alternate method using ClickDetector instead. Thank you to those that attempted to assist me.

script.Parent.Access.ClickDetector.MouseClick:Connect(function(player)
	local key = player.Backpack:FindFirstChild("Key")
	if key and readytoOpen then
		if door == false then

			game.ReplicatedStorage.RemoteEvent:FireClient(player)

			-- Rest of the code

		elseif door == true then

			game.ReplicatedStorage.RemoteEvent:FireClient(player)

			-- Rest of the code
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.