Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

function OnTouch(hit) glitch?

Asked by 9 years ago

I'm working on a game, and I made some throwing knives for it. (no, it is not a murder mystery game.) I made it so when you throw it, it clones an onTouch script, but the function isn't firing off when it's supposed to. Basically, when it hits a brick, it anchors the knife to make it stick to the part. For some reason, it hits it, but it waits a few miliseconds, THEN it anchors it. If you need a better description, go to my game http://www.roblox.com/MURDER-WARS-BETA-SHOP-place?id=144396722 and throw some of the knives, and you notice that they don't anchor the second they hit that part. Any help? script that clones into the throwing knife:

local sounds = {
script.hit1,
script.hit2
}
function OnTouch(hit)
script.Parent.Anchored = true
sounds[math.random(1,#sounds)]:Play()
local humanoid = hit.Parent:FindFirstChild("Humanoid") 
if (humanoid ~= nil) then
local ids = {
146594648,
146594640
}
sound = Instance.new("Sound",script.Parent)
sound.Volume = 1
sound.SoundId = "rbxassetid://146594640"
sound:Play()
humanoid.Health = 0
wait(10)
script.Parent:Destroy()
end
end
script.Parent.Touched:connect(OnTouch)

Answer this question