Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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)
0
It's saying FindFirstChildHumanoid is not a valid member of model Dockboy20006 10 — 5y
0
Oops, I made a typo. Try again. royaltoe 5144 — 5y
0
Made another typo actually, I forgot quotes around humanoid royaltoe 5144 — 5y
0
should be good now royaltoe 5144 — 5y
View all comments (3 more)
0
pls mark as answered / comment if it's not working when you see this royaltoe 5144 — 5y
0
Thank you so much bro! Dockboy20006 10 — 5y
0
no thank u royaltoe 5144 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

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

0
you can't turn of fe anymore royaltoe 5144 — 5y
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 royaltoe 5144 — 5y
0
ok thanks royal Cynical_Innovation 595 — 5y

Answer this question