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

How to combine remote events and ontouched event?

This is the sender (server script)

-- Server script
Detector = script.Parent.DetectorFront
Reset = true
local Players = game:GetService("Players")
cameraA = game.ReplicatedStorage.cameraA

Detector.Touched:connect(function(hit)
	local plr = hit.Parent
	if plr:FindFirstChild("Humanoid") then
		if Reset == true then
			local Player = hit.Parent
			cameraA:FireClient(Player)
			Reset = false
			wait(20)
			Reset = true
		end
	end
end)

This is the script that should answer the server script (local script)

--local script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait()
local Camera = workspace.CurrentCamera
local TA = workspace:WaitForChild("Bosses")
local TB = TA:WaitForChild("Red")
local TC = TB:WaitForChild("Red")
local target = TC:WaitForChild("Humanoid")
local player = Players.LocalPlayer
local cameraA = ReplicatedStorage:WaitForChild("cameraA")

cameraA.OnClientEvent:connect(function()
	print("accepted")
    Camera.CameraSubject = target
wait(5)
	Camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end)

I keep getting the error: "Player argument has to be a player object roblox" The script should fire cameraA remote event when the player touches the detector and then the localscript should make the player watch a certain brick

1 answer

✓ Accepted answer

Hit.Parent is not the player, but rather the player’s character. To get the player instead of the character, you can use GetPlayerFromCharater with the character as an argument.

Detector.Touched:connect(function(hit)
    local char = hit.Parent
    if char:FindFirstChild("Humanoid") then
        if Reset == true then
            local Player = game.Players:GetPlayerFromCharacter(char)
            cameraA:FireClient(Player)
            Reset = false
            wait(20)
            Reset = true
        end
    end
end)

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