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

The Remote Event is not working?

Asked by 3 years ago
Edited 3 years ago

So when I play the game and touch the part that should Fire the Remote Event nothing happens and there is no problems or anything in the output. I'm not sure what is happening, I tried searching but still no solution

-- Server Script

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then


        game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow"):FireClient(game:GetService("Players"):GetPlayerFromCharacter(hit.Parent))

    end
end)

-- ================================================================

-- Local Script

game:GetService("ReplicatedStorage"):FindFirstChild("DestroyArrow").OnClientEvent:Connect(function()

    script.Parent:Destroy()
    game.Workspace.Spawn.Arrow:Destroy()
    print("Done")

end)


0
where did u put the local script Nguyenlegiahung 1091 — 3y
0
the script has to be a child of the part to work. JustinWe12 723 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Edit: You're destroying the script before you do what the RemoteEvent is intended to do, I would destroy the script's parent when complete. I use assertions, they return errors if they fail. If you find it in the output don't worry about it.

You should use the methods that Roblox has provided in their API Reference.

-------------------
--[[ Server Script ]]

local Players: Players = game:GetService("Players")
local ReplicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent: RemoteEvent = ReplicatedStorage:WaitForChild("DestroyArrow");

script:FindFirstAncestorWhichIsA("BasePart").Touched:Connect(function(BasePart: BasePart)
    local Character: Model = BasePart:FindFirstAncestorWhichIsA("Model"); assert(Character);
    local Humanoid: Humanoid = Character:FindFirstChildWhichIsA("Humanoid"); assert(Humanoid);
    local Player: Player = Players:GetPlayerFromCharacter(Character); assert(Player);

    return RemoteEvent:FireClient(Player);
end)
-------------------
--[[ LocalScript ]]

local ReplicatedStorage: ReplicatedStorage = game:GetService("ReplicatedStorage");
local RemoteEvent: RemoteEvent = ReplicatedStorage:WaitForChild("DestroyArrow");

RemoteEvent.OnClientEvent:Connect(function()
    workspace:WaitForChild("Spawn", math.huge):WaitForChild("Arrow", math.huge):Destroy()
    script:Destroy()
end)
Ad

Answer this question