I have a script that automatically equips the first tool in the players backpack but for some reason when the tool equips it wont let me click with the tool or use "tool.activated* event but when I disable the script that auto equips it works perfectly fine, ALSO I have a script that uses an ability when I press “E” on my tool and that works perfectly fine just not the click.
Auto Tool Equip Script:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local Tool = plr.Backpack:GetChildren()[1]
char.Humanoid:EquipTool(Tool)
end)
end)
Im not sure what in this script could be stopped my attacking script from working. Any help is greatly appreciated.
Try parenting the tool to the character instead of using Humanoid:EquipTool, although if the character is already holding a tool you will need to unequip it first (you can use Humanoid:UnequipTools to do so before you set the parent)
Can you send your tool script? It’s quite hard for us to know what’s going on after the tool is activated.
Since I tested your server script with a tool that has some functions and it seems to work completely fine, it’s probably to do with your tool’s script or localscript.
As @soprosostupid said, ideally we would need to see both the Tool’s LocalScript and the server Script that has the “OnServerEvent” connection for the RemoteEvent. The reason why is that there is a possibility that the LocalScript is correctly firing the RemoteEvent, but something in the server Script is preventing the code from executing like a malfunctioning debounce for example
local clientCast = require(game.ServerStorage.ClientCast)
local debounce = false
local slash
for i = -0.9,3.8,.1 do
local attachment = Instance.new("Attachment",script.Parent.Handle)
attachment.Name = "DmgPoint"
attachment.Position = Vector3.new(0,i,0)
end
local casterParams = RaycastParams.new()
casterParams.FilterDescendantsInstances = {script.Parent.Parent.Parent.Character or script.Parent.Parent.Parent.Parent.Character, script.Parent.Handle}
local slashCaster = clientCast.new(script.Parent.Handle, casterParams)
slashCaster.Collided:Connect(function(result)
local Tool = script.Parent
local ToolP = Tool.Parent
local sound = Tool.Handle.Hit
local h = Tool.Parent:FindFirstChild("Humanoid")
local hFrame = Tool.Parent:FindFirstChild("HumanoidRootPart")
local hit = result.Instance
local hithumanoid = hit.Parent:FindFirstChild("Humanoid")
if hit.name == "Hitbox" or hithumanoid then
local bv = Instance.new("BodyVelocity")
local offset = Vector3.new()
bv.MaxForce = Vector3.new(10000000,10000000,10000000)
bv.Velocity = h.Parent.Head.CFrame.LookVector * 55
bv.Parent = (hithumanoid.Parent.HumanoidRootPart)
wait(0.01)
bv:Destroy()
if hithumanoid.Parent:FindFirstChild("Effects") then
if not hithumanoid.Parent.Effects:FindFirstChild("Ragdoll") then
local z = Instance.new("BoolValue", hithumanoid.Parent.Effects)
z.Name = "Ragdoll"
local Debris = game:GetService("Debris")
Debris:AddItem(z, 2.5)
task.wait(0.1)
if not debounce then
debounce = true
sound:Play()
local Effect = game.ReplicatedStorage.VFX.HitBlock:Clone()
Effect.Parent = game.Workspace.HitEffects
Effect.CFrame = hFrame.CFrame * CFrame.new(0, -1, -4)
Effect.hitFx:Emit(5)
local Debris = game:GetService("Debris")
Debris:AddItem(Effect,0.5)
local KnockOut = Instance.new("ObjectValue")
KnockOut.Name = "KnockOut"
KnockOut.Value = ToolP
KnockOut.Parent = hithumanoid.Parent
Debris:AddItem(KnockOut, 6)
task.wait(0.2)
debounce = false
end
end
end
end
end)
script.Parent.Equipped:Connect(function()
local humanoid = script.Parent.Parent:FindFirstChild("Humanoid")
if not slash then slash = humanoid:LoadAnimation(script.Animation); slash.Priority = Enum.AnimationPriority.Action3 end
end)
script.Parent.Attack.AttackEvent.OnServerEvent:Connect(function()
local ss = script.Parent.Handle.Swing
print("serverevent")
slash:Play()
task.wait(0.2)
ss:Play()
slashCaster:Start()
wait(.5)
slashCaster:Stop()
end)
script.Parent.Unequipped:Connect(function()
if slash then slash:Stop() end
slashCaster:Stop()
end)
local script that fires remote event
local db = false
script.Parent.Activated:Connect(function()
if not db then
db = true
print("activated")
script.AttackEvent:FireServer()
wait(3)
db = false
end
end)
@soprosostupid i tried both of the things y’all said and it still not working, again when I disable the “ForceEquipServer”(First script i sent) it works fine so im not sure whats stopping it from firing the remote event.
Are you getting any errors when you check the output? If so, please tell us what they say (Also it would be helpful if you say where the RemoteEvent is located please)
The remote event is parented to the local script that’s parented to the tool as what I know. Btw did it print anything by adding a print to debug after the .OnServerEvent handler?
I will keep up later as I’m on my phone. But may you give us a photo of the character’s descendants in game after equipped? And also try to add more prints to parts of the code, such as when it fires the remote etc. and check which part exactly it went wrong.
Wait actually, the forceequip script as you given is a localscript, but there’s things like player.playeradded? Just make it autoequip with localplayer.humanoid
Took me a while but here’s the finished script (must be a server script parented to the tool for it to work correctly!):
local debris = game:GetService"Debris"
local clientCast = require(game:GetService"ServerStorage".ClientCast)
local tool = script.Parent
local handle = tool.Handle
coroutine.wrap(function() -- I don't know what's the point of this loop since it doesn't seem to do anything so consider removing it
local newInstance = Instance.new
local yAxisVector3 = Vector3.yAxis
for f = -0.9, 3.8, 0.1 do
local attachment = newInstance"Attachment"
attachment.Name = "DmgPoint"
attachment.Position = f * yAxisVector3
attachment.Parent = handle
end
end)()
local slash, slashCaster
local debounce
local hitBlock = game:GetService"ReplicatedStorage".VFX.HitBlock
local hitEffects = game:GetService"Workspace".HitEffects
tool.Equipped:Once(function() -- Will only run once so don't worry about memory leaks
slash = tool.Parent.Humanoid.Animator:LoadAnimation(script.Animation)
slash.Priority = Enum.AnimationPriority.Action3
local casterParams = RaycastParams.new()
casterParams.FilterDescendantsInstances = {tool.Parent}
casterParams.FilterType = Enum.RaycastFilterType.Exclude
slashCaster = clientCast.new(handle, casterParams)
slashCaster.Collided:Connect(function(result)
local hit = result.Instance
local hitHumanoid = hit.Parent:FindFirstChildWhichIsA"Humanoid"
if hit.Name == "Hitbox" or hitHumanoid then
local bodyVelocity = Instance.new"BodyVelocity"
bodyVelocity.MaxForce = Vector3.one * 10000000
bodyVelocity.Velocity = tool.Parent.Head.CFrame.LookVector * 55
bodyVelocity.Parent = hit.Parent.PrimaryPart
debris:AddItem(bodyVelocity, 0)
if hit.Parent:FindFirstChild"Effects" and not hit.Parent.Effects:FindFirstChild"Ragdoll" then
local ragdoll = Instance.new"BoolValue"
ragdoll.Name = "Ragdoll"
ragdoll.Parent = hit.Parent.Effects
debris:AddItem(ragdoll, 2.5)
if debounce then return end
debounce = true
handle.Hit:Play()
local effect = hitBlock:Clone()
effect.CFrame = tool.Parent.PrimaryPart.CFrame * CFrame.new(0, -1, -4)
effect.hitFx:Emit(5)
effect.Parent = hitEffects
debris:AddItem(effect, 0.5)
local knockout = Instance.new"ObjectValue"
knockout.Name = "KnockOut"
knockout.Value = tool.Parent
knockout.Parent = hit.Parent
debris:AddItem(knockout, 6)
task.wait(0.2)
debounce = nil
end
end
end)
end)
local debounce
tool.Activated:Connect(function()
if debounce then return end
debounce = true
print"activated"
slash:Play()
task.wait(0.2)
handle.Swing:Play()
slashCaster:Start()
task.wait(0.5)
slashCaster:Stop()
task.wait(3)
debounce = nil
end)
tool.Unequipped:Connect(function()
slashCaster:Stop()
if slash.IsPlaying then slash:Stop() end
end)
I also discovered that the LocalScript and the RemoteEvent aren’t really necessary in your case as you don’t seem to be sending any data from the client to the server so feel free to delete them if my script works
Oh yeah just found out. The serverscript side only handles animations after serverevent, which is unnecessary as animations will be automatically replicated, so firing the remote event is not required after all. Nice script organisation!