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

Question about RemoteEvents from Script to Server?

Asked by 6 years ago

Hello,

I have a Script that's held by a Part, attached to a part inside the Player, when it touches an opposing player, it should both do damage, and send a RemoteEvent. It does the damage, but when it sends the RemoteEvent, its not receiving the request correctly. I think I'm getting the syntax wrong here.

Question: Is FireClient () and OnServerEvent:Connect(function() the correct things to be using here to send the request from a Script, not a LocalScript, to another script on the Server?

Abbreviated Script inside the Part:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EXPEvent = RR:WaitForChild("EXPEvent")

local character = script.Parent.Parent
local player = game.Players:GetPlayerFromCharacter(character.Parent.Parent.Parent)


if player then
    local damage = 100
        local x = script.Parent.Parent.Weapon
        x.Touched:Connect(function(x)
            if x.Parent:FindFirstChild("Humanoid") and x.Parent.Name ~= player.Name then
                x.Parent.Humanoid:TakeDamage(damage)
                EXPEvent:FireClient(player) -- Sends the RemoteEvent Request

            end
        end)        
end

and then the Script inside ServerScriptStorage:

EXPEvent.OnServerEvent:Connect(function(player)
    wait(2)
        player.leaderstats.Experience.Value = player.leaderstats.Experience.Value + 10 
end)

I'm not getting any errors, except when I tried changing the OnServerEvent to OnClientEvent and it told me I could only do that from client scripts.

Thanks!

1 answer

Log in to vote
1
Answered by 6 years ago

No, actually.

What you need to understand is FilteringEnabled (FE for short). You use RemoteEvents when sending data from the client to server or vice versa. However, when you want to communicate between Scripts, you need to use BindableFunctions and BindableEvents. RemoteEvents are specifically for the client to the server.

For more info, read this.

0
Thank you for this! I knew nothing of Bindable Events/Functions before, but this fixed that. :) Now I just need to get Touch script to stop going so much upon touch, and its all good to go. Thanks again! Never2Humble 90 — 6y
0
And done. :) Many thanks again! Never2Humble 90 — 6y
Ad

Answer this question