Remote event from replicatedstorage tool not being fired?

hi, im trying to make my own simple sword combat system, but ive suddenly ran into one issue.

i have buttons that allow you to change which sword you spawn with, which grabs the selected sword type’s tool from replicated storage and clones it, parenting it to the players backpack.

this code is in a script in startergui under a screengui and frame, it gets the swords folder from replicated storage and then the sword which is inside of the folder

image

this code is part of the same script as the image above, detecting when the image button is clicked and cloning the sword from replicated storage, then putting it into the players backpack

the sword is given to the player correctly, but then the sword’s remote event isnt firing, meaning the player that it hits isnt going to take any damage.

this is the code inside of the server script thats inside of the tool, it is the main problem i am having as the server event inside of it isnt firing when it supposedly should be

this is the code inside of the tools local script, it detects when the hitbox part of the sword is touched by a player and plays a sound, prints a message and tries to fire off to the server script mentioned before so the hit player takes damage. the remote event isnt printing or firing properly for some reason

this is the sword inside of the folder inside of replicated storage

image

ive tried to move the location of the sword tools folder and the tool itself, not having any luck. ive also tried to see if anyone has had any similar problems, but i couldnt find anything.

help would be greatly appreciated

1 Like

Is the remote event on the client side being fired from the localscript?

yes, it is

the sword waits for a humanoid to hit the hitbox then it tries to do the remote event

also, very fitting name for this post haha

Does it print “Player hit” or anything to suggest the remote is actually firing?

If not, what is hitbox.Touched?

Not willing to offer any help on this code, but please submit formatted blocks of code with proper names so we know what code is for what file. It is not our job to figure out your structure. Thanks!

1 Like

everything thats on the client works fine, it even plays the sound and prints “player hit”
the only thing that doesnt work is re:FireServer(hit.Parent), so i only ever get the hit detection from the client and not the server

hitbox is a part that’s attached to the tool and is only able to be touched if the debounce isnt true

got it, ill make a quick edit so its more understandable

1 Like

made some edits to make the code more clear

Why don’t you move the remote event into the tool and have the server script in the tool (preferred) and then just do script.Parent.RemoteEvent.OnServerEvent (you get it).

Or since your remote event is inside ReplicatedStorage why don’t you just have 1 server script to handle that (first option is way more common).

i had it like this beforehand, the sword strangely worked completely fine if it was in StarterPack, but ever since i had tried to grant the player the sword through cloning it in replicated storage, its remote event had stopped working

Can I confirm you are cloning the tool using a server script and not a local script? Maybe it’s a dumb question.

the cloning is done through the local script inside of a gui in startergui

it deletes all previous tools and then gives the clone of the selected tool to the player

should i be using server scripts to give the player the tool instead?

Well going back to when you tried to use a remote event inside of the tool (the preferred way of doing things).

If you are only cloning using a LocalScript then the server script will not run and will not handle the remote event since it literally doesn’t exist on the server and only exists on the client.

You should clone using a server script (basically).

Just saw the photo you attached for your new system:

image

The “Script” will not run if you are cloning it with a LocalScript - this is likely the issue.

okay, i’ll try that,
just to make sure though i should have a remote event in replicated storage that the local script in the gui activates, then a script in serverscriptservice that is linked to the remote event to give the player the tool?

Well what I would do is create another remote event inside the ReplicatedStorage called GiveSword and then add a server script in server script service with the following code:

local rs = game:GetService("ReplicatedStorage")
local giveSword = rs:FindFirstChild("GiveSword")

giveSword.OnServerEvent:Connect(function(player)
      if not player then end 
      if not player.Backpack then end

      task.spawn(function()
          for _, tool in pairs(player.Backpack:GetChildren()) do
              if tool:IsA("Tool") then tool:Destroy() end
          end
      end)
      local swordClone = sword:Clone() -- you need to define sword
      swordClone.Parent = player.Backpack
end)

Sorry for the poor formatting I’m typing this on devforum. I also added some sanity checks for good practice.

And then change the local script in your gui to this:

local rs = game:GetService("ReplicatedStorage")
local giveSword = rs:WaitForChild("GiveSword")

swordbutton.MouseButton1Click:Connect(function()
      giveSword:FireServer()
end)

And that will ensure the server does the cloning and handling for the sword tool.

This should work with your current layout.

1 Like

i managed to find a way to make it work using the local script, by making a separate remote event dedicated to giving the player the sword, as well as moving the remote event that deals the damage into its own area in replicatedstorage

im sure your solution would be a lot better but ive been stuck on this for around an hour and im glad to finally have results

Glad to hear it.

Just remember that if you’re cloning a tool (or any other instance) that contains a server script using a local script then the server script will not run as it only exists on the client.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.