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

Not a valid member of Workspace?

Asked by
ExcelUp 24
5 years ago

I have a script in ServerScriptService that should wait 5 seconds and pick a number between 1 and 3. It should then choose which crate to get from the ReplicatedStorage from the random number selected. These three crates are 'weaponCrate', 'armorCrate' and 'beveragesCrate'. It should then fire an event to the client, so that the client can enable GUI stating that a crate is about to spawn. The crate selected should then be cloned, parented to the Workspace, and given a new name 'spawnedCrate'. The crate (which is a model by the way) should then move to the position of a part in the Workspace called 'crateSpawnLocationA', and then a sound should play, parented to the script. FilteringEnabled is ON.

When I run the script however, I get an error saying 'crateSpawnLocationA is not a valid member of Workspace'. I've tried to use FindFirstChild(), and I get an error saying 'Cannot index a nil value', and I've also tried to use WaitForChild(), but I get an error saying 'Infinite yield possible at game:GetService("Workspace").crateSpawnLocationA'. I've tried turning FilteringEnabled off, but that hasn't effected anything.

Can someone please help me?

My code is below:

wait(5)

crateNumber = math.random(1,3)
if crateNumber == 1 then
    crate = game:GetService("ReplicatedStorage").weaponCrate
elseif crateNumber == 2 then
    crate = game:GetService("ReplicatedStorage").armorCrate
elseif crateNumber == 3 then
    crate = game:GetService("ReplicatedStorage").beveragesCrate     
end
game:GetService("ReplicatedStorage").crateSpawned:FireAllClients(crateNumber)
crate = crate:Clone()
crate.Parent = game:GetService("Workspace")
crate.Name = "spawnedCrate"
crate:MoveTo(game:GetService("Workspace").crateSpawnLocationA.Position)
script.Sound:Play()
0
Have you checked that the spelling and capitalisation of the name 'crateSpawnLocationA' is the exact same in workspace as in the script? Have you also checked that the spawn location part is directly inside workspace, not inside something else in workspace? mattscy 3725 — 5y
0
Yes, 'crateSpawnLocationA' is the exact name in the Workspace as in the script, and 'crateSpawnLocationA' is DIRECTLY inside the Workspace, not inside a model. ExcelUp 24 — 5y
0
Is it also anchored and/or cancollided so it doesnt fall through the floor and delete itself? mattscy 3725 — 5y
0
no... LOL ExcelUp 24 — 5y
View all comments (2 more)
0
So that's the problem? loool mattscy 3725 — 5y
0
Yes, thank you, lmfao. ExcelUp 24 — 5y

Answer this question