Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to combine remote events and ontouched event?

Asked by 6 years ago

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

Log in to vote
3
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

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)
Ad

Answer this question