I know this is a really simple problem but I’m pretty new to scripting but I’d like to fix this problem as I am getting this simple basic error that I know how to fix but I quite can’t:
“Character is not a valid member of ‘Player.ThoifeDev’”
I’ve fixed these types of errors with no problem, but the problem is I hate using normal scripts instead of local scripts.
The mission of this script is to let a certain user go in if their name is exclusively this, it’s post to be a bed-type thing for only devs in my game and if you touch it and you’re not a dev then it will teleport you.
Code:
script.Parent.Touched:Connect(function(hit)
if hit.Parent.Character and hit.Parent.Name == "ThoifeDev" then
script.Parent.CanCollide = false
else
hit.Parent.Character.HumanoidRootPart.CFrame = CFrame.new(119.61, 0.5, -180.22)
end
end)
The main line that’s causing me problems is line 3, probably line 5 too.
I just need to find the character as I’ve done before but I’ve never tried this type of thing.
hit.Parent is already the character model, so you can just do
if hit.Parent and hit.Parent.Name == "ThoifeDev" then
script.Parent.CanCollide = false
else
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(119.61, 0.5, -180.22)
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('Humanoid') ~= nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player.Name == 'ThoifeDev' then
script.Parent.CanCollide = false
else
player.Character.HumanoidRootPart.CFrame = CFrame.new(119.61, 0.5, -180.22)
end
end
end)
Also @lluckvyplayer might be defined as nil if you’re not implementing any conditional checks with it & the script detects a hit.Parent that is not a valid Player Object
script.Parent.Touched:Connect(function(hit)
if hit.Parent and hit.Parent.Name == "ThoifeDev" then
script.Parent.CanCollide = false
else
hit.Parent:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(119.61, 0.5, -180.22)
end
end)