Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

My remote event isn't firing, why?

I'm working on a script, it's basically some special powers(The force from star wars). Now to the point. One of the powers kills other plays by slowly damaging them 15 damage, plus an animation. Now, I've used Mouse.Target to get the humanoid. When I use the script on a NPC it works perfectly. However, when I use it on another player, all damage is only local to me and the animation doesn't work. All of this is done via a localscript.

So therefore I decided to re-do the script and switch to a remote event and use :FireServer(). Here's what the new remote event script looks like.

script:WaitForChild("RemoteEvent).OnServerEvent(function()
	print("Server fired")
	local Target = script.Parent
	local Loader = Target:LoadAnimation(script:WaitForChild("ChokeForce"))
	Loader:Play()
	Target.Walkspeed = 0
	Target.Health = Target.Health-15
	wait(0.68)
	Target.Health = Target.Health-15
	wait(0.68)
	Target.Health = Target.Health-15
	wait(0.68)
	Target.Health = Target.Health-15
	wait(0.68)
	Target.Health = Target.Health-15
	Target.Health = 0
end)

That script is taken and placed into the target(The one getting killed)'s humanoid. And this is the PART of the script that fires the remote event.

if Mouse.Target.Parent:FindFirstChild("Humanoid") then

print("Humanoid found")

Target = Mouse.Target.Parent:FindFirstChild("Humanoid")

Clone = script.Parent.KillScript:Clone()

Clone.Parent = Target

wait()

Target:FindFirstChild("KillScript"):WaitForChild("RemoteEvent"):FireServer()

Disregard the missing end as it isn't missing in the original script. Now to the point, the event that is fired is taken and placed inside of the player's humanoid and fires in there. The :FireServer() is located inside of a tool the localplayer is holding. Yet, nothing out of it. No error output, it doesn't print the "Server fired" which indicates that it isn't firing. Does anyone know the issue?

10 comments

0

I suggest re arranging the location of everything. You can put the RemoteEvent in the ReplicatedStorage, the ServerScript in the ServerScriptService. Next change some variables and it should work

0

you: all of this is done via a localscript. also you: the damage is only local to me. Did u try putting it in a normal script?

0

You'll also want to put Connect between OnServerEvent(function() I believe

0

Thanks for the quick reply. Responding to vissequ: There is a :Connect. I just forgot to add in here while typing it out. Responding to VVickedDev: I can't move it to a normal script since I need a localscript to get the mouse of the local player in order to may a KeyDown function. Responding to BlackOrange3343: I'll be trying that out, I'll add a comment to tell you the result.

0

BlackOrange, I've changed what I could. The remote event is now in replicated storage. It actually fired but the one that fired was the one located inside my tool and not the one that was place inside of my target. And the script that fires the remote event can't be placed inside of ServerScriptService as it's for a tool, and not a power for everyone in the server.

0

Adding on to my comment above. In order to fix the incorrect script from firing I've attempted to disable the one located inside of my tool. And the copy placed inside of my target's humanoid is enabled. No effect, nothing occurred. Not sure what to do.

0

if you message me on discord vissequ#1301 i can take a look at the project file

0

For the first line that's receiving the fired event, use a " and a :Connect

0

Ex: script:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(Put Your Passing Arguments Here (Ex: damage, health,dead)) Ex: script:WaitForChild("RemoteEvent").OnServerEvent:Connect(function(player,damage,health)

0

:WaitForChild("RemoteEvent) nice

1 answer

✓ Accepted answer

Your script isn't working because you are working against Filtering Enabled. You are cloning a server script on the client making it not replicate to other players.

Your approach should be to make a Remote Event that gets information from the client to damage them.

SeverScript:

RemoteEvent.OnServerEvent:Connect(function(sender, arg1)
    --sender is the Player object that used :FireServer()
    --arg1 is whatever the local player sends
    --in this case, arg1 is the humanoid
    
    local targetHumanoid = arg1
    
    local animation = targetHumanoid:LoadAnimation()
    animation:Play()
    
    targetHumanoid.WalkSpeed = 0
    
    repeat
	    targetHumanoid:TakeDamage(15) --damage humanoid 15
	    wait(.68)
    until (targetHumanoid.Health <= 0) --dead check
    
end)

LocalScript:

local arg1 = workspace.Dummy.Humanoid
RemoteEvent:FireServer(arg1)
--arg1 doesn't have to be named the same, just for sake of explaination

Note: RemoteEvent is assumed to be in a place where the server and client can access. It is also assumed it is already defined as a variable.

From this all you have to do is :FireServer() on the client and it will trigger the event on the server. The server will then replicate the damage to all clients and the NPC or player will appear dead on everyone's screen.

But just because it works doesn't mean you should keep it like that! This RemoteEvent would be exploitable as the server does no checking to see if it's valid. The server should check if they:

  1. Are able to use that ability
  2. Are close enough to activate that ability
  3. Are following the cooldown of that ability
  4. etc.

Hope this helps!

1 comment

0

Appreciated, works as expected.

This discussion is preserved as it was. New answers, comments, and votes are closed.