When a player touches a certain part, I want to make it so a model currently in Workspace (named GameModel) goes into ServerStorage and is replaced with another model (named PlayAgainModel) that was previously stored in ServerStorage. I’m also teleporting the player to PlayAgainModel.
The issue is that when the script gets to the line where it’s told to move GameModel to ServerStorage, in the output there is an error that says “GameModel is not a valid member of Workspace”.
Here is the code:
local void = script.Parent
local fallen = false
void.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and fallen == false then
fallen = true
local character = hit.Parent
local HRP = character.HumanoidRootPart
HRP.Anchored = true
for i, v in pairs(character:GetChildren()) do
if v:IsA("Part") and v ~= HRP then
v.Transparency = 1
end
end
game.ServerScriptService.GameplayScript.Disabled = true
workspace.GameModel.Parent = game.ServerStorage
game.ServerStorage.PlayAgainModel.Parent = workspace
HRP.CFrame = CFrame.new(0, 5, 0)
for i, v in pairs(character:GetChildren()) do
if v:IsA("Part") and v ~= HRP then
v.Transparency = 0
end
end
HRP.Anchored = false
fallen = false
end
end)
It may seem silly but are you sure all the spellings are correct? Scripting is really picky like that.
Another issue may be that the model itself has been destroyed at some point during the simulation so that it’s no longer in the workspace. Just because something may be in the workspace to start with doesn’t necessarily mean it’s always there! For example, it could have fallen into the void and been destroyed?
I’ve done some tests and have noticed that the Touched event is always running twice, which would explain the error. I’m still unsure of why it runs twice since I have the variable “fallen” set from false to true as soon as the event is fired and set back to false when the player would no longer be near “void”.
I made it so at the end of the event the script gets disabled, making it so it doesn’t fire more than once. Still wish I knew why the event was fired twice but this still works.