I’m not sure if i’ve phrased it well in the title but at the moment I’m trying to make an ability activates when I press a button. I know that I need to use userinputservice for this but I don’t have any experience with adding to or changing a model’s humanoid.
To make it easier as an example, how would I create a sword appearing in a player’s hand, task.wait(1), and then disappearing?
You can use Player.StarterGear, and with some waiting, you can remove it:
local tool = *tool*
local player = *player*
local timeToWait = 3 -- (example)
local debounce = false
put this after the part where it’s supposed to add:
if not debounce then
debounce = true
tool.Parent = player.StarterGear
wait(timeToWait)
if player.StarterGear:FindFirstChild(tool.Name) then
if player.Backpack:FindFirstChild(tool.Name) then
player.Backpack[tool.Name]:Destroy()
end
player.StarterGear[tool.Name]:Destroy()
end
end
If this is not what you want, can you help me understand with your script?
Thanks for the idea, but i’m not trying to use tools in my game. It’s more like this specific ability makes a sword on a player’s hand, uses it to slash, and then fades out of existance. At the moment, I’m not sure how to create this ability. What I assume is happening (correct me if I’m wrong) in the code snippet you gave me is a tool the player can equip, something i’m not going for in my game.
I have got a question:
- Where is the sword localized? LeftArm, RightArm?
- What type of rig are the players? (because left arms’ and right arms’ names are different in R15 than in R6)
- I’m not sure what you mean by localised, but if you mean the part they are stuck to, right arm (right hand)
- the players are r15
local sword = *sword*
local player = *player*
local timeToWait = 3 -- (example)
local debounce = false
put this after the part where it’s supposed to add:
if not debounce and player.Character.Humanoid.Health > 0 then
debounce = true
sword.Parent = player.Character["Right Arm"]
wait(timeToWait)
if player.Character["Right Arm"]:FindFirstChild(sword.Name) then
player.Character["Right Arm"][sword.Name]:Destroy()
end
end
I meant like where it’s supposed to be parented. What it’s parent?
Thanks, I’ll give this a try whenever I get the chance and if it works I’ll mark it as solution
Have you tried the code yet?
Did it work?