Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I am entirely confused of why this works on one game but not this one?

I honestly don't know why this isn't working, it works on my other game, exact same scripting, exact locations of all models and names, I just don't understand. Please someone help.

Error: Workspace.Part3.Script:10: attempt to index local 'Player' (a nil value)

local Players = game:GetService('Players')
local debounce = false
local Teleport = "Part4" 
function onTouched(hit)
	if debounce == false then
		debounce = true
	local OnTouchSky = game.ServerStorage.SkyChanger2
	local OnTouchSkyCopy = OnTouchSky:Clone()
	local Player = Players:FindFirstChild(hit.Parent.Name)
	   	if Player.PlayerGui:FindFirstChild("SkyChanger") then
			if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
				local Pos = script.Parent.Parent:findFirstChild(Teleport)
				hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false
			end
	        Player.PlayerGui.SkyChanger:Destroy()
		    OnTouchSkyCopy.Parent = Player.PlayerGui
			debounce = false
	else
		if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
				local Pos = script.Parent.Parent:findFirstChild(Teleport)
				hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false script.Parent.Parent:findFirstChild(Teleport).Locked = false
			end
			OnTouchSkyCopy.Parent = Player.PlayerGui
			debounce = false
	    end
	end
end
script.Parent.Touched:Connect(onTouched)

2 answers

✓ Accepted answer

You're not checking if the thing touching the part is a valid player:

Here's how you'd check

local Players = game:GetService('Players')
local canTouch = true
local Teleport = "Part4"
 
function onTouched(hit)
	local isPlayer  = hit.Parent:FindFirstChild("Humanoid")
	if(isPlayer)then
	    if canTouch then
			canTouch = false
			local player = game.Players:FindFirstChild(hit.Parent.Name)
		    local OnTouchSky = game.ServerStorage.SkyChanger2
		    local OnTouchSkyCopy = OnTouchSky:Clone()
		
	        if player.PlayerGui:FindFirstChild("SkyChanger") then
	            if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then
					script.Parent.Locked = true script.Parent.Parent:findFirstChild(Teleport).Locked = true
	                local Pos = script.Parent.Parent:findFirstChild(Teleport)
	                hit.Parent:moveTo(Pos.Position) 
					wait(1) 
					script.Parent.Locked = false 
					script.Parent.Parent:findFirstChild(Teleport).Locked = false
				end
	
	            player.PlayerGui.SkyChanger:Destroy()
	            OnTouchSkyCopy.Parent = player.PlayerGui
	    	else
	        	if script.Parent.Locked == false and script.Parent.Parent:findFirstChild(Teleport).Locked == false then script.Parent.Locked = true 
					script.Parent.Parent:findFirstChild(Teleport).Locked = true
	                local Pos = script.Parent.Parent:findFirstChild(Teleport)
	                hit.Parent:moveTo(Pos.Position) wait(1) script.Parent.Locked = false
					script.Parent.Parent:findFirstChild(Teleport).Locked = false
	            end
	            OnTouchSkyCopy.Parent = player.PlayerGui
	        end
	    end
    	canTouch = true
	end
end
script.Parent.Touched:Connect(onTouched)

7 comments

0

It's saying FindFirstChildHumanoid is not a valid member of model

0

Oops, I made a typo. Try again.

0

Made another typo actually, I forgot quotes around humanoid

0

should be good now

0

pls mark as answered / comment if it's not working when you see this

0

Thank you so much bro!

0

no thank u

it also could be not working bc one game has filtering enabled off and this one has it on. if not then do what royaltoe says

3 comments

0

you can't turn of fe anymore

0

i think the issue was that the part in the other game wasnt touching anything else so it wasnt erroring where as this part is touching things in game so its causing the error

0

ok thanks royal

This discussion is preserved as it was. New answers, comments, and votes are closed.