✓ Accepted answer
Local Scripts don't work in workspace
Local Scripts don't work in workspace, unless they're in a character.
For your script, as Kingdom5 mentioned, you don't need to use a Remote Event. Remote events are used for Server to Client, or Client to Server communication. Because we can do everything in a Regular Script, we don't need remote functions.
script.Parent.Touched:connect(function(part)
print(part.Name)
end)
Prints the name of the part that touched the object
Getting Characters from a Touched Event,
Sometimes you might want to get a character that touches the part. How do we know it's a Character? Well, all characters have a thing called a Humanoid inside them. All we have to do, is check if the parent of the part has a Humanoid.
script.Parent.Touched:connect(function(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if humanoid then
local character = part.Parent
print(character.Name)
end
end)
Prints the name of the character, if there is one, that touched the object
Getting a Player from a Touched Event
The other one works for NPCs too. It works for anything with a Humanoid, and sometimes we want the Player, not the Character. We can use the :GetPlayerFromCharacter function of the Players to do this very easily.
script.Parent.Touched:connect(function(part)
local plr = game.Players:GetPlayerFromCharacter(part.Parent)
if plr then
print(plr.Name)
end
end)
Prints player name
If we wanted to get the character and only if it's a player, we can use .Character on any player. Example,
local plr = "DefinePlayer")
local char = plr.Character
Gets character from player
Good Luck!
if I helped, please don't forget to accept my answer
2 comments
You do not need a remote event for the touched event, this can be done by a server script wiht FE on.
Thank you, I'll try.