@huner2
This is an anonymous function.
@QuestionCreator
If you want an anonymous function (this means that can be called once per connections) then use what huner2 wrote.
Otherwise just do what did you do but remove the "()", those aren't used in lua.
local part = game.Workspace.YourPartName
function onTouch(part)
print("Hello!")
end
part.Touched:connect(onTouch)
If you want to do something to the player who touched the part then you need first to create a local script, then declare the LocalPlayer variable:
local player = game.Players.LocalPlayer
And then execute your function
function onTouch(part)
player.Character.Humanoid.Health = 0
end
game.Workspace.YourNamePart.Touched:connect(onTouch)
If you want that to be called in the SERVER (Normal Script) and not in the CLIENT (Local Script) then you need to get the player who touches the part by doing this:
local players = game.Players:GetChildren()
local player
function getPlayer()
game.Players.PlayedAdded:connect(function(p)
player = p
end
end
function onTouch(part)
player.Character.Humanoid.Health = 0
end
game.Workspace.YourNamePart.Touched:connect(onTouch)
getPlayer()
2 comments
Strangely I tried to remake this script to learn stuff and it did not work
Output?