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!
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.