Cool thing about GetPlayerFromCharacter() is that it can get the Player as well as the Player's Character for example:
script.Parent.Touched:connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
Player.Character
Player.Character.Humanoid.Health = 50
end)
Now lets implement this new feature about GetPlayerFromCharacter()that you learnt into your script. One of the Problem I can notice is that if a Part like the Baseplate triggers your touch event script the script will error since GetPlayerFromCharacter() will return nil which will lead to rest of your code not working. To prevent this I suggest adding a if statement to check if it was a Player that triggered the event.
local Debounce = false
script.Parent.Touched:connect(function(hit)
local person = game.Players:GetPlayerFromCharacter(hit.Parent)
if person and Debounce ~= true then
Debounce = true
person.Backpack.CutsceneScript:Destroy()
local c = game.Workspace.CurrentCamera
c.CameraType = "Custom"
wait()
c.CameraSubject = person.Character:FindFirstChild("Humanoid")
print(person.Name)
end
Debounce = false
end)
1 comment
Is this in a LocalScript?