✓ Accepted answer
Strange way of hooking up the touch event.
neverless, the way you've formatted it is slightly squeed, you need to close the if statement with a then
Like:
if script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Enemy") then
Hit.Parent.Enemy.creator.Value = script.Parent.Firer.Value
end
end) then needed since the if statement doesnt have a then word
end
A better and a more coherent(straight forward) way of doing this is the following:
local TouchedEvent = script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Enemy") then
Hit.Parent.Enemy.creator.Value = script.Parent.Firer.Value
end
end)
local timesrun = 0
if TouchedEvent then
print("Touched event hooked up!")
timesrun = timesrun+1
print("timesrun = "..(timesrun))
end
You dont need to hook up the event top a value since just calling script.Parent.Touched:connect(function(Hit) end) is good enough to get the job done.
Final correct way to do this code:
script.Parent.Touched:Connect(function(Hit)
if Hit.Parent:FindFirstChild("Enemy") then
Hit.Parent.Enemy.creator.Value = script.Parent.Firer.Value
end
end)
hope this helps! :)
2 comments
you have an extra end
@0fficialHen There's an extra end because there's 2 if statement which 1 isn't, and a function. The only problem is this person just needs to remove the "if" on line 1 and remove the 2 end and that'll solve it.