The gist of the program I've written is for a user to touch a part, and then create a variable called "owner" that is equal to their player ID. Right now, I'm just trying to print the owner/UserID. Except the output keeps displaying "Connection - Server - Script:17" before I even touch the part. Which is why I'm wondering, is the "playerId" variable not allowed to be returned to the event function call? And if so, how can I create a variable outside the scope of a function equal to a variable inside the scope of the function? (And also, if anybody knows, what "Connection - Server - Script:17" means?)
local Players = game:GetService("Players")
local touch2claim = script.Parent.touch2claim
local function claim(otherPart)
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
local playerId = player.UserId
return playerId
end
end
local owner = touch2claim.Touched:Connect(claim)
print(owner)
I'm fairly new to programming on Roblox. So any help is appreciated!
EDIT: I think I may have solved it. Here is my new code:
local Players = game:GetService("Players")
local touch2claim = script.Parent.touch2claim
local owner = nil
local otherPart = touch2claim.Touched:Wait()
local partParent = otherPart.Parent
local humanoid = partParent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
local player = Players:GetPlayerFromCharacter(character)
local playerId = player.UserId
owner = playerId
end
print(owner)
Feedback is appreciated!

4 comments
the way you're explaining is kinda confusing to me.
If there is a way I can clear it up, I will gladly do so.
i mean i understand, but beginners might don't understand
Fair enough, although it isn't an easy topic to understand either, especially for beginners.