Ok, so what I want to do is hit a stationary object, like a non-moving brick. I want to hit it with a tool that has a script in the Handle and has the same animation as a Linked Sword. Here's the script.
enabled = true function onTouched(h) if enabled == true then if h.Name == "PUTIS" then -- The stationary object's name that the tool will hit if h.Transparency ~= 1 then enabled = false h.Parent.Humanoid.Health = h.Parent.Humanoid.Health - 25 -- The stationary object has a humanoid. Whenever touched with the tool's handle, it will decrease by 25 health. wait(1) enabled = true end end end end script.Parent.Touched:connect(onTouched)
There is no output error. For some reason, the script won't do anything when I'm (the player) is stationary and hitting the stationary object. This should work since the tool is moving, allowing the Touched script to activate, but it only works when the player himself/herself is moving. I'm looking for a fix to this problem or maybe an alternative solution that doesn't include a Touched script.
A tip when creating Touched event scripts, use print to see what the object is actually hitting before you set property things like names and such, as your previous code,
EDIT: Sword modification final result. This should work. If not change hit.Name to hit.Parent.Name for PUTIS. You can modify the animation or add your custom animation to the functions in the code.
-- Remodification of the Sword. r = game:service("RunService") sword = script.Parent.Handle Tool = script.Parent function blow(hit) if (hit.Parent == nil) then return end print(hit.Name) local humanoid = hit.Parent:findFirstChild("Humanoid") local vCharacter = Tool.Parent local vPlayer = game.Players:playerFromCharacter(vCharacter) local hum = vCharacter:findFirstChild("Humanoid") if humanoid~=nil and humanoid ~= hum and hum ~= nil then -- If a player is hit do stuff here. else if hit.Name == "PUTIS" then hum.Health = hum.Health - 25 end end end function attack() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Slash" anim.Parent = Tool end function lunge() local anim = Instance.new("StringValue") anim.Name = "toolanim" anim.Value = "Lunge" anim.Parent = Tool force = Instance.new("BodyVelocity") force.velocity = Vector3.new(0,10,0) force.Parent = Tool.Parent.Torso wait(.25) swordOut() wait(.25) force.Parent = nil wait(.5) swordUp() end function swordUp() Tool.GripForward = Vector3.new(-1,0,0) Tool.GripRight = Vector3.new(0,1,0) Tool.GripUp = Vector3.new(0,0,1) end function swordOut() Tool.GripForward = Vector3.new(0,0,1) Tool.GripRight = Vector3.new(0,-1,0) Tool.GripUp = Vector3.new(-1,0,0) end function swordAcross() -- parry end Tool.Enabled = true local last_attack = 0 function onActivated() if not Tool.Enabled then return end Tool.Enabled = false local character = Tool.Parent; local humanoid = character.Humanoid if humanoid == nil then print("Humanoid not found") return end t = r.Stepped:wait() if (t - last_attack < .2) then lunge() else attack() end last_attack = t Tool.Enabled = true end script.Parent.Activated:connect(onActivated) connection = sword.Touched:connect(blow)
use onHit instead.
I don't know if bumping works in this forum, but I haven't gotten activity in this thread. This isn't an answer, only a post to get more attention on this issue.