Hey there! Basically I have a script that clones a tool from ReplicatedStorage into the player’s backpack when they buy that item, but when the player tries to use it, the local script in that item doesn’t fire an event. I’ve tried testing if the event would fire while the tool was in StarterPack and it worked. It just doesn’t work when the item gets cloned for some reason.
Local script:
local plr = game.Players.LocalPlayer
local cooldown = false
local Character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script:WaitForChild("ThrowAnimation"))
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
animation:Play()
script.ThrowEvent:FireServer() -- The event
wait(1) --time for cooldown
cooldown = false
end
end)
Once the event fires this script should start running:
local ts = game:GetService("TweenService")
script.Parent.OnServerEvent:Connect(function(plr)
wait(0.3) --startup
local torso = plr.Character.UpperTorso
local sound = script.Parent.Parent.ThrowSound:Clone()
sound.Parent = torso
sound:Play()
game.Debris:AddItem(sound,1)
local Honeybun = game.ReplicatedStorage.MicrowavedHoneyBunHitbox:Clone()
local DamageValuee = Honeybun.MicrowavedHoneyBun.DamageValue.Value
Honeybun.Parent = game.Workspace
Honeybun.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.lookVector * 5
ts:Create(Honeybun, TweenInfo.new(3, Enum.EasingStyle.Linear),{CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 65}):Play()
game.Debris:AddItem(Honeybun,3) -- dissapear time
local touched = false
Honeybun.Touched:Connect(function(hit)
if hit.Parent.Name == "Noob" or hit.Parent.Name == "DiamondNoob" or hit.Parent.Name == "BigNoob" or hit.Parent.Name == "SmartNoob" and touched == false then
touched = true
hit.Parent.Humanoid:TakeDamage(DamageValuee)
Honeybun:Destroy() -- damage dealt
if hit.Parent.Humanoid.Health <= 0 then
plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + hit.Parent.MoneyValue.Value
end
wait(1)
touched = false
end
end)
end)
Analyzing all possibilities, this seems to be a case where your server event-listener function is never connected, or that the script is never ran. This lands my suspicion on your method of “cloning” the tool to the player’s backpack. How exactly are you handling it? Are you cloning and parenting the tool from a LocalScript or on the server (especially considering your tool is in ReplicatedStoarge, that clients are able to see)?
local plr = game.Players.LocalPlayer
local cooldown = false
local Character = plr.Character or plr.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local animation = humanoid:LoadAnimation(script:WaitForChild("ThrowAnimation"))
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ThrowEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ThrowEvent") -- you can change this to what ever you like but If you want to use this make a folder called "RemoteEvents" and make the RemoteEvent in that folder.
script.Parent.Activated:Connect(function()
if cooldown == false then
cooldown = true
animation:Play()
ThrowEvent:FireServer() -- Use the RemoteEvent directly
wait(1)
cooldown = false
end
end)
And there’s your problem. You’re handling the tool cloning and parenting locally, and hence why your server-side of your tool is never ran. Simply handle the tool cloning and parenting on the server and your issue in question will be fixed.
Why is this happening? Because the server has absolutely no idea what’s going on. When you do absolutely anything non-communicative on LocalScripts, the server does not see it and hence here, you cloning your tool to the player’s Backpack on the client side, the server doesn’t even know the player has the tool, let alone recognizing the script and RemoteEvent parented to it, hence only the client counterparts of the descendants of the tool are run. The RemoteEvent is also fired, but there’s nothing to listen for the signal.
This moreover depends on what’s happening in the LocalScript itself. As you mentioned “if the player has enough money”, where the money is actually stored and how is it being checked is what you’d need to account for. I’m assuming you’re storing “money” and checking if player has enough all on the client (in a LocalScript), which is something I would highly recommend against due to the possibility of this being wrongfully manipulated by the client.
I would suggest implementing some additional validation-based remote communication so that when the player attempts to get the tool, if the player has “money” is checked on the server instead of on the client, and then clone and parent the tool if so, in a standard server-script.
If you’re confused about anything or have any questions, don’t hesitate to ask.