Ive been scripting for a day and i have problem with this script, i keep getting a error

This is the script
myvar = game.Workspace.xD

myvar.Touched:Connect(function(hit) local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent) if player then
game.workspace.xD.Anchored = false
wait(1)
end
end)

this is the error
xD is not a valid member of Workspace “Workspace”

btw “xD” Is a model with 2 parts in it

1 Like

Is this a regular script or a local script?

Pokemoncraft5290 its a script

Can you show the explorer? Tyos happen.

xD is a model, try this:

local xdModel = game.Workspace.xD:GetChildren()

for _, obj in pairs(xdModel) do
    if obj:IsA("BasePart") then
        obj.Touched:Connect(function(hit)
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if player then
                obj.Anchored = false
            end
        end)
    end
end

When the error is that xD doesn’t exist, changing what you do with xD won’t help.

2 Likes

I remember coming across a similar issue, could you try this?

local myvar = game.Workspace:WaitForChild("xD")

myvar.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        mrvar.Anchored = false
    end
end)

If it infinite yields, you probably put it in the wrong parent

It should belong inside the workspace alone & not parented somewhere else

1 Like

Try checking the spelling and use waitforchild?

local myvar = game:GetService("Workspace"):WaitForChild("xD")