Event not firing correctly

So I have been making a cutscene so that when I pull a lever, it will play a cutscene with the camera going to the target of a part. I tried firing it to the player. But it gave me an error: player argument must be a Player object. And I tried doing the userId and it still gave me the same result but with userId.

This is my script so far (server script)

local target = script.Parent.Gate
local tweenservice = game:GetService("TweenService")
local lever1 = script.Parent.Parent.Handle.Lever.Handle2
local lever2 = script.Parent.Parent.Handle.Lever.Part

local function gateOpen()
	local tweeninfo = TweenInfo.new(
		3.6,
		Enum.EasingStyle.Cubic,
		Enum.EasingDirection.In,
		0,
		false,
		0
	)


	local gateOpen = tweenservice:Create(target, tweeninfo, {CFrame = target.CFrame + Vector3.new(0, 10, 0)})

	gateOpen:Play()

	--lever pull down anim
	local tweeninfo2 = TweenInfo.new(
		0.3,
		Enum.EasingStyle.Cubic,
		Enum.EasingDirection.Out,
		0,
		false,
		0
	)

	local leverDown1 = tweenservice:Create(lever1, tweeninfo2, {CFrame = lever1.CFrame * CFrame.new(0, -0.8, 0)})
	local leverDown2 = tweenservice:Create(lever2, tweeninfo2, {CFrame = lever2.CFrame * CFrame.new(0, -0.8, 0)})

	script.Parent.Open:Play()
	leverDown1:Play()
	leverDown2:Play()
end

local function setup(player: Player)
	local proximityPrompt = Instance.new("ProximityPrompt")
	proximityPrompt.Parent = lever2.Parent.Parent
	proximityPrompt.ActionText = ""
	proximityPrompt.Triggered:Connect(function()
		proximityPrompt:Destroy()
		gateOpen()
		game.ReplicatedStorage.Events:WaitForChild("GateOpen"):FireClient(player) --error here
	end)
end

setup()

1st Local script inside startercharacterscripts

local rs = game:GetService("RunService")
local part = workspace:WaitForChild("LookCam")
local offset = CFrame.new(0,0,0)
local cam = workspace.CurrentCamera
local event = game.ReplicatedStorage.Events:WaitForChild("GateOpen")

while wait() do
	part.CFrame = cam.CFrame * offset
end
event.OnClientEvent:Connect(function()
	script:Destroy()
end)

2nd local script

local ts = game:GetService("TweenService")
local part = workspace:WaitForChild("LookCam")
local parttarget = workspace:WaitForChild("LookCamTarget")
local camera = workspace.CurrentCamera

local tweeninfo = TweenInfo.new(
	1,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local tween = ts:Create(part, tweeninfo, {CFrame = parttarget.CFrame})
--(will continue later)

If anyone could help me, I would be glad.

Your setup() function doesn’t need the player argument inside the parentheses, and instead the proximity prompt trigger needs it.

-- Example
local button = game.Workspace.Part.ProximityPrompt

button.Triggered:Connect(function(player)
	print(player) -- should print the player who interacted with it
end)
1 Like

you need to add the player in the parameter, since this is a server script that isnt possible without a remote event sending the player to my knowledge. I think for your case you could use :FireAllClients since you want all the players in the server to see the cutscene. If you only want the player to see the cutscene you need a client —> server → client connection.

That being said do you need to create the proximity prompt in a script? Cant you do that in the workspace and studio?

1 Like

Thanks! It actually works! I didn’t notice that in the first place!

Oh i see setup doenst play the cutscene my bad you might want to use :FireAllClients

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.