This post is old and should not be solved, the system I attempted to use was really bad and full of bad practices
The problem was likely with a CustomEquip script I wrote (for some reason)
Which messed with tool equipping
Old Post
I have a script for my tool that waits for the tool to be equipped and defines the player’s character but returns backpack
Code:
script.Parent.Equipped:Wait()
Character = script.Parent.Parent
(It’s not laggy as the recording shows)
Edit:
I NEED the wait so I can LOAD ANIMATIONS
5 Likes
use Tool.Equipped
function instead of script.Parent.Equipped:Wait()
so the whole thread won’t yield until the Tool is equipped.
1 Like
I need to wait so I can get the character to load animations
add a delayyyyyyyyyyyyyyyyyyyyyyyyyyyy
1 Like
Not working
Ignore:
gftrjihfdobnhiucloihudfsblbhjif
1 Like
I did a little testing and just as your example shows it doesn’t print when the tool had RequiresHandle toggled on but turning that off fixed it. Maybe try that?
1 Like
if the script is a localscript, there is no need to do this. you can just do
local Character = player.Character or player.CharacterAdded:Wait()
if it’s a serverscript, you can probably do
local Character = script:FindFirstAncestorOfClass("Player").Character
RequiresHandle is off
My already used code has worked every other time when using it and I intend on using it
this is kinda confusing because you’re saying that it works but it’s actually not working, but try this
script.Parent.Equipped:Wait()
repeat wait() until script.Parent.Parent.Name ~= "Backpack"
Character = script.Parent.Parent
I am saying that this code has worked in other tools I have made
Also the error still occurs
i was looking at your code but ok
Here is all the related code:
Hierarchy:
Main:
--------------------------------Variables--------------------------------
local Animations = {}
local MRTouchedPlr = nil
local AnimBusy = false
local SmiteBusy = false
local SwingBusy = false
local Damage = false
----------------------------------Code-----------------------------------
--Wait until tool is equiped
script.Parent.Equipped:Wait()
task.wait(0.1)
Character = script.Parent.Parent
local LocalPlayer = game:GetService("Players"):GetPlayerFromCharacter(Character)
if Character.Humanoid.RigType ~= Enum.HumanoidRigType.R15 then
warn("Invalid RigType (R6)")
script.Parent:Destroy()
task.wait(99^99)
end
--Load Animations
for _, v in pairs(script.Parent:WaitForChild("Anims", 1):GetChildren()) do
Animations[v.Name] = Character.Humanoid.Animator:LoadAnimation(v)
end
--Tool Logic
script.Parent.Events.Smite.OnServerInvoke = function(Player: Player)
if Player == LocalPlayer then
if not AnimBusy and not SmiteBusy then
AnimBusy = true
SmiteBusy = true
Animations.Smite:Play(0.4)
local SThread = coroutine.create(function()
while true do
if Character.Humanoid.WalkSpeed ~= 0 then
OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.WalkSpeed = 0
end
wait()
end
end)
if Character.Humanoid.UseJumpPower then
local OldJumpPower = Character.Humanoid.JumpPower
local OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.JumpPower = 0
Character.Humanoid.WalkSpeed = 0
local JThread = coroutine.create(function()
while true do
if Character.Humanoid.JumpPower ~= 0 then
OldJumpPower = Character.Humanoid.JumpPower
Character.Humanoid.JumpPower = 0
end
wait()
end
end)
coroutine.resume(JThread)
coroutine.resume(SThread)
Animations.Smite.Ended:Wait()
coroutine.close(JThread)
coroutine.close(SThread)
Character.Humanoid.JumpPower = OldJumpPower
Character.Humanoid.WalkSpeed = OldSpeed
else
local OldJumpHeight = Character.Humanoid.JumpHeight
local OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.JumpHeight = 0
Character.Humanoid.WalkSpeed = 0
local JThread = coroutine.create(function()
while true do
if Character.Humanoid.JumpHeight ~= 0 then
OldJumpHeight = Character.Humanoid.JumpHeight
Character.Humanoid.JumpHeight = 0
end
wait()
end
end)
coroutine.resume(JThread)
coroutine.resume(SThread)
Animations.Smite.Ended:Wait()
coroutine.close(JThread)
coroutine.close(SThread)
Character.Humanoid.JumpHeight = OldJumpHeight
Character.Humanoid.WalkSpeed = OldSpeed
wait(10)
SmiteBusy = false
end
AnimBusy = false
end
end
end
script.Parent.Activated:Connect(function()
if not AnimBusy and not SwingBusy then
print("sdvfl,knjhvdsljknbvfjkm,bhfm njb")
AnimBusy = true
SwingBusy = true
Damage = true
Animations.Swing:Play(0.4)
Animations.Swing.Ended:Wait()
AnimBusy = false
Damage = false
wait(0.05)
SwingBusy = false
end
end)
script.Parent.Handle.Touched:Connect(function(TouchPart: BasePart)
if Damage then
local Player = game:GetService("Players"):GetPlayerFromCharacter(TouchPart.Parent)
if Player and Player ~= MRTouchedPlr and Player ~= LocalPlayer then
MRTouchedPlr = Player
Player.Character.Humanoid:TakeDamage(5)
end
end
end)
Anim: (also encounters the error described)
local Character
script.Parent.Equipped:Connect(function()
Charactor = script.Parent.Parent
local RightGrip = Charactor.RightHand:WaitForChild("RightGrip", 1)
local NewRightGrip = Instance.new("Motor6D")
NewRightGrip = Instance.new("Motor6D")
NewRightGrip.Parent = Charactor.RightHand
NewRightGrip.Name = "RightGrip"
NewRightGrip.Part0 = RightGrip.Part0
NewRightGrip.Part1 = RightGrip.Part1
NewRightGrip.C0 = RightGrip.C0
NewRightGrip.C1 = RightGrip.C1
RightGrip:Destroy()
end)
script.Parent.Unequipped:Connect(function()
Charactor.RightHand:WaitForChild("RightGrip", 1):Destroy()
end)
CustomEquip:
script.Parent.Pickaxe.Handle.Touched:Connect(function(TouchPart)
local Player = game.Players:GetPlayerFromCharacter(TouchPart.Parent)
if Player then
Player.Character.Humanoid:EquipTool(script.Parent)
end
end)
1 Like
Sorry I was moving it to a reply to that guy so that he get’s updated on the situation
2 Likes
This really isn’t related but this wouldn’t work in the first place…
First of all to my knowledge your running animations on the server, that’s bad practice but not impossible.
Second of all unless your only trying to do this once, scripts inside of a tool do NOT restart after unequipping and reequipping them, just add a script to the tool and don’t change anything, you will figure that out fast.
Third your creating a grip for your tool I’m guessing, that does NOT need to be done as tools automatically do this.
Fourth your whole system is run by server scripts, I won’t say this is terrible but it’s not good, generally (from my experience as a developer) you should NOT do everything inside of a server script. It is good to know when to use local scripts, when to use server scripts, and when to use remoteEvents to transfer data inbetween. (but of course all of this is just from some developer who only has two years behind his belt so, )
also take all of this with a grain of salt and don’t come at me if I was wrong about something I don’t want do deal with the hassle of fixing some mistake I made while explaining
oh and to answer how to fix your original problem, idek
It does
Thanks I’ll make sure to do that
I know
I’m not
Explanation of my code and why I need it:
Main
--------------------------------Variables--------------------------------
local Animations = {} --I need this to store animations
local MRTouchedPlr = nil --Used to make sure one player is damaged a bunch
local AnimBusy = false --Make sure multiple animations don't play at the same time
local SmiteBusy = false --Used for smite ability cooldown
local SwingBusy = false --Used for swing cooldown
local Damage = false --Used to know when to damage players
----------------------------------Code-----------------------------------
--Wait until tool is equiped (I do this so that I get a reference to the player's character to load animations off of, why isn't this in Equipped:Connect()? So I don't load animations every time the tool is equipped)
script.Parent.Equipped:Wait()
Character = script.Parent.Parent
local LocalPlayer = game:GetService("Players"):GetPlayerFromCharacter(Character) --Used for checks
if Character.Humanoid.RigType ~= Enum.HumanoidRigType.R15 then --Animations won't work with R6
warn("Invalid RigType (R6)")
script.Parent:Destroy()
task.wait(99^99)
end
--Load Animations
for _, v in pairs(script.Parent:WaitForChild("Anims", 1):GetChildren()) do
Animations[v.Name] = Character.Humanoid.Animator:LoadAnimation(v)
end
--Tool Logic
script.Parent.Events.Smite.OnServerInvoke = function(Player: Player)
if Player == LocalPlayer then --Make sure the player is the tool owner
if not AnimBusy and not SmiteBusy then --Make sure animations aren't playing and that smite isn't on cooldown
AnimBusy = true
SmiteBusy = true
Animations.Smite:Play(0.4) --Play animation requires fading time of 0.4 to be smooth
local SThread = coroutine.create(function() --A used to freeze the player's place and if their speed is updated it will be changed to that updated speed once animation is finished
while true do
if Character.Humanoid.WalkSpeed ~= 0 then
OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.WalkSpeed = 0
end
wait()
end
end)
if Character.Humanoid.UseJumpPower then --JumpPower Check
local OldJumpPower = Character.Humanoid.JumpPower
local OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.JumpPower = 0
Character.Humanoid.WalkSpeed = 0
local JThread = coroutine.create(function()
while true do
if Character.Humanoid.JumpPower ~= 0 then
OldJumpPower = Character.Humanoid.JumpPower
Character.Humanoid.JumpPower = 0
end
wait()
end
end)
coroutine.resume(JThread) --Call thread
coroutine.resume(SThread) --Call thread
Animations.Smite.Ended:Wait() --Wait for animation to end
coroutine.close(JThread) --Close thread
coroutine.close(SThread) --Close thread
Character.Humanoid.JumpPower = OldJumpPower --Restore JumpPower
Character.Humanoid.WalkSpeed = OldSpeed --Restore Speed
wait(10)
SmiteBusy = false
else
local OldJumpHeight = Character.Humanoid.JumpHeight
local OldSpeed = Character.Humanoid.WalkSpeed
Character.Humanoid.JumpHeight = 0
Character.Humanoid.WalkSpeed = 0
local JThread = coroutine.create(function()
while true do
if Character.Humanoid.JumpHeight ~= 0 then
OldJumpHeight = Character.Humanoid.JumpHeight
Character.Humanoid.JumpHeight = 0
end
wait()
end
end)
coroutine.resume(JThread)
coroutine.resume(SThread)
Animations.Smite.Ended:Wait()
coroutine.close(JThread)
coroutine.close(SThread)
Character.Humanoid.JumpHeight = OldJumpHeight
Character.Humanoid.WalkSpeed = OldSpeed
wait(10)
SmiteBusy = false
end
AnimBusy = false
end
end
end
script.Parent.Activated:Connect(function() --Swing
if not AnimBusy and not SwingBusy then
print("sdvfl,knjhvdsljknbvfjkm,bhfm njb") --Print function since I forgot to add AnimBusy = false
AnimBusy = true
SwingBusy = true
Damage = true
Animations.Swing:Play(0.4)
Animations.Swing.Ended:Wait()
AnimBusy = false
Damage = false
wait(0.05)
SwingBusy = false
end
end)
script.Parent.Handle.Touched:Connect(function(TouchPart: BasePart) --Responsible for damaging players
if Damage then
local Player = game:GetService("Players"):GetPlayerFromCharacter(TouchPart.Parent) --Get player
if Player and Player ~= MRTouchedPlr and Player ~= LocalPlayer then --Check if player exists and is the the tool owner or most recently touched player
MRTouchedPlr = Player
Player.Character.Humanoid:TakeDamage(5) --Damage
end
end
end)
Anim
local Character --Character variable
script.Parent.Equipped:Connect(function()
Charactor = script.Parent.Parent --Get character
--Replace normal RightGrip with Motor6D RightGrip (needed for animations to work properly)
local RightGrip = Charactor.RightHand:WaitForChild("RightGrip", 1)
local NewRightGrip = Instance.new("Motor6D")
NewRightGrip = Instance.new("Motor6D")
NewRightGrip.Parent = Charactor.RightHand
NewRightGrip.Name = "RightGrip"
NewRightGrip.Part0 = RightGrip.Part0
NewRightGrip.Part1 = RightGrip.Part1
NewRightGrip.C0 = RightGrip.C0
NewRightGrip.C1 = RightGrip.C1
RightGrip:Destroy()
end)
script.Parent.Unequipped:Connect(function()
--Destroy Motor6D RightGrip
Charactor.RightHand:WaitForChild("RightGrip", 1):Destroy()
end)
CustomEquip
--Used to equip the tool to the player if they touch the actual pickaxe model and not just the handle
script.Parent.Pickaxe.Handle.Touched:Connect(function(TouchPart)
local Player = game.Players:GetPlayerFromCharacter(TouchPart.Parent)
if Player then
Player.Character.Humanoid:EquipTool(script.Parent)
end
end)
So I was bored, couldn’t figure out why your tool wasn’t working and decided to just remake it…
It has mostly all the concepts your code had.
from what I could see it seems to be a weapon? Correct me if I’m wrong.
anyways heres the model: https://create.roblox.com/store/asset/16320408509/Pickaxe%3Fkeyword=&pageNumber=&pagePosition=
Here’s the one I currently have
What u want me to do wit it???
I was assuming you recreated mine to debug it
I mainly recreated it not for debugging but because it was made up of bad practices, like running everything in server scripts, as well as some other stuff like the way you did hit detection using. Touched and some other stuff, but I mainly did it because I was bored and couldn’t figure out how to fix your problem. So, in a way, yes and no.