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:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02local EXPEvent = RR:WaitForChild("EXPEvent")
03 
04local character = script.Parent.Parent
05local player = game.Players:GetPlayerFromCharacter(character.Parent.Parent.Parent)
06 
07 
08if player then
09    local damage = 100
10        local x = script.Parent.Parent.Weapon
11        x.Touched:Connect(function(x)
12            if x.Parent:FindFirstChild("Humanoid") and x.Parent.Name ~= player.Name then
13                x.Parent.Humanoid:TakeDamage(damage)
14                EXPEvent:FireClient(player) -- Sends the RemoteEvent Request
15 
16            end
17        end)       
18end

and then the Script inside ServerScriptStorage:

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

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