✓ Accepted answer
There is always a way around things like this. When you script, there are tons of way to do it. In this case I suggest a function mainly to identify the player.
If you actually want the Player object
local Part = script.Parent
local function getPlayer(Char)
if game:GetService('Players'):GetPlayerFromCharacter(Char) then
return game:GetService('Players'):GetPlayerFromCharacter(Char)
else
return nil
end
end
local Debounce = true
Part.Touched:Connect(function(Hit)
if not Debounce then return end
if Hit.Parent:FindFirstChild('Humanoid') then
Debounce = false
local Player = getPlayer(Char)
wait()
Debounce = true
end
end)
So basically, you first check if there is a Humanoid to the Hit. Next check for a humanoid object and if there is then check if it's a player. If it's not a player Player will be nil. If it is a player it will return the player.
Hopefully this helped! Basically you can split up your code
Best of luck developer!
BlackOrange3343
PS: If you want the name, change return game:GetService('Players'):GetPlayerFromCharacter(Char) to return game:GetService('Players'):GetPlayerFromCharacter(Char).Name
OR
replace --Do stuff with local PlayerName = Player.Name. I returned the full player because it gives you more properties to work with.
3 comments
Since you're connecting the function, it has nowhere to return to. Return will give back a value to whatever called the function. You also have an unused parameter called "plr" since the Touched event only provides one argument to connected functions. You might want to check out https://developer.roblox.com/api-reference/function/Players/GetPlayerFromCharacter
return player.Name
http://xyproblem.info