Workspace is not a valid member of Workspace "Workspace"

Hello,
I am creating my soccer game on roblox and I am developing a goalkeeper mode I made a script that allows you to take the ball,
I tested and I had a problem when I take the ball in my hand and I click and its put me “Workspace is not a valid member of Workspace” Workspace "I saw whole pages of forum and its not helping me

Code:local dropped = false

script.Parent.Activated:Connect(function()
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent
wait(0.0001)
print(plr.Name)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
elseif f == “Red” then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
wait(0.001)
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == 1 then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = false
else
game.Workspace.Players.Red[plr.Name].BallDropped.Value = false
end
script:Destroy()
end
end)

while script.Parent.Parent.Name == “Backpack” do
wait(5)
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent.Parent
wait(0.0001)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
elseif f == “Red” then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
game.Workspace.SoccerBall.SoccerBall.Position = plr.Character.Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == 1 then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = false
else
game.Workspace.Players.Red[plr.Name].BallDropped.Value = false
end
script:Destroy()
end
end

  1. Please use codeblocks to make your code readable.
  2. What line is erroring?
local dropped = false

script.Parent.Activated:Connect(function()
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent
wait(0.0001)
print(plr.Name)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
elseif f == “Red” then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
wait(0.001)
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == 1 then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = false
else
game.Workspace.Players.Red[plr.Name].BallDropped.Value = false
end
script:Destroy()
end
end)

while script.Parent.Parent.Name == “Backpack” do
wait(5)
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent.Parent
wait(0.0001)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
elseif f == “Red” then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
game.Workspace.SoccerBall.SoccerBall.Position = plr.Character.Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == 1 then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = false
else
game.Workspace.Players.Red[plr.Name].BallDropped.Value = false
end
script:Destroy()
end
end

game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)

What does this print output? aa

to see if is nil or playerName

No, I’m asking what it is printing. Is it outputting your name correctly?

no it says “Workspace”

Try removing 1 .Parent on this line.

it works, I can click even in my player test it works but after I re-test its my put an error "fares14213 is not a valid member of Folder ,Workspace.Players.Red "

The problem is that the Players folder is in game.Players.(PlayerName) not game.Workspace.Players.(PlayerName)

I did that not work
Code:local dropped = false

script.Parent.Activated:Connect(function()
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent
wait(0.0001)
game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
wait(0.001)
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
plr:WaitForChild(“BallDropped”).Value = true
wait(6)
plr:WaitForChild(“BallDropped”).Value = false
script:Destroy()
end
end)

while script.Parent.Parent.Name == “Backpack” do
wait(5)
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent.Parent
wait(0.0001)
game.Workspace.SoccerBall.SoccerBall.Position = plr.Character.Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
plr:WaitForChild(“BallDropped”).Value = true
wait(6)
plr:WaitForChild(“BallDropped”).Value = false
script:Destroy()
end
end

Error: 00:24:09.016 Infinite yield possible on ‘Workspace.fares14213:WaitForChild(“BallDropped”)’ - Studio
00:24:09.017 Stack Begin - Studio
00:24:09.017 Script ‘Players.fares14213.Backpack.Ball.Script’, Line 18

when we click

can you send a screenshot of the entire output so we can see which line it is?

theres no 2nd instance of Workspace under Workspace, you should be able to understand what that means.

If this line is in fact the error then plr.Name is == “Workspace” and thats your error, but send a screenshot of output

game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)

also here:

 Infinite yield possible on ‘Workspace.fares14213:WaitForChild(“BallDropped”)’ - Studio

balldropped doesnt exist on the player apparently

there is no error when I click it does not give it to me in my inventory here is the code:local dropped = false

script.Parent.Activated:Connect(function()
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent
wait(0.0001)
print(plr.Name)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
end
elseif f == “Red” then
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
end
end
end
game.Workspace.SoccerBall.SoccerBall.Position = game.Workspace[plr.Name].Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
wait(0.001)
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == “Blue” then
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
end
elseif f == “Red” then
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
end
end
end
script:Destroy()
end
end)

while script.Parent.Parent.Name == “Backpack” do
wait(5)
if dropped == false then
local plr = nil
dropped = true
local Ballc = script.Parent
plr = script.Parent.Parent.Parent.Parent
wait(0.0001)
local f = 0
for i,v in pairs(game.Workspace.Players.Blue:GetChildren()) do
if v.Name == plr.Name then
f = “Blue”
end
end
for i,v in pairs(game.Workspace.Players.Red:GetChildren()) do
if v.Name == plr.Name then
if f == 0 then
f = “Red”
end
end
end
if f == “Blue” then
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
end
elseif f == “Red” then
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
end
end
end
game.Workspace.SoccerBall.SoccerBall.Position = plr.Character.Head.Position + Vector3.new(3,0,0)
game.Workspace.SoccerBall.SoccerBall.Transparency = 0
game.Workspace.SoccerBall.SoccerBall.Anchored = false
game.Workspace.SoccerBall.SoccerBall.CanCollide = true
local Script = script
Script.Parent = game.Workspace
Ballc:Destroy()
wait(6)
if f == “Blue” then
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
end
end
elseif f == “Red” then
if game.Workspace.Players.Red:FindFirstChild(plr.Name) then
game.Workspace.Players.Red[plr.Name].BallDropped.Value = true
else
if game.Workspace.Players.Blue:FindFirstChild(plr.Name) then
game.Workspace.Players.Blue[plr.Name].BallDropped.Value = true
end
end
end
script:Destroy()
end
end

just send a screen shot of the output

it’s good I managed to fix


So I have had weird errors like that before (PlayerGui is not a valid member of game.Players.Lava_shield) and I fixed the issue by putting a wait(1) at the start of the script. I am not sure your issue can be fixed this easily but I would try it.

exactly at the start of my game it happened to me I wait (0.001) and it works nicely

But the wait(0.001) doesn’t work this time I am guessing?

well me it works well


in short I’m going to sleep, for me the time is 1 AM