Hello Developers!
Today i was trying to make a script that moves guis after they click play button. There is an error always appearing in output and it says “CarSpawner is not valid member on playerGui” but there is a CarSpawner gui in playerGui, i would like what is wrong (I am totaly new in scripitng)
Here is the script:
local PlayButton = script.Parent.MainMenuBackground.HoverPlay
local background = script.Parent.Parent.CarSpawner:WaitForChild("BackgroundFrame")
local SpawnButton = script.Parent.Parent.CarSpawner:WaitForChild("SpawnCarButton")
local RemoveButton = script.Parent.Parent.CarSpawner:WaitForChild("RemoveCarButton")
local Opened = false
PlayButton.MouseButton1Click:Connect(function()
if not Opened then
Opened = true
wait(1.5)
background:TweenPosition(UDim2.new(0.011, 0,0.741, 0),"InOut","Quint", 0.5, true)
SpawnButton:TweenPosition(UDim2.new(0.017, 0,0.756,0),"InOut","Quint", 0.5, true)
RemoveButton:TweenPosition(UDim2.new(0.016, 0,0.872,0),"InOut","Quint", 0.5, true)
for i = 0,10,1 do
wait()
end
end
end)
local PlayButton = script.Parent.MainMenuBackground.HoverPlay
local background = script.Parent:WaitForChild("BackgroundFrame")
local SpawnButton = script.Parent:WaitForChild("SpawnCarButton")
local RemoveButton = script.Parent:WaitForChild("RemoveCarButton")
local Opened = false
PlayButton.MouseButton1Click:Connect(function()
if not Opened then
Opened = true
wait(1.5)
background:TweenPosition(UDim2.new(0.011, 0,0.741, 0),"InOut","Quint", 0.5, true)
SpawnButton:TweenPosition(UDim2.new(0.017, 0,0.756,0),"InOut","Quint", 0.5, true)
RemoveButton:TweenPosition(UDim2.new(0.016, 0,0.872,0),"InOut","Quint", 0.5, true)
for i = 0,10,1 do
wait()
end
end
end)
Your script open/close is inside the CarSpawner GUI therefore there’s no need to go outside or the GUI to get objects which are inside the GUI. I’d suggest using the code above and report back if it works.
if CarSpawner is in StarterGui then this should fix your problem.
local PlayButton = script.Parent.MainMenuBackground.HoverPlay
local background = game:GetService("StarterGui").CarSpawner.BackgroundFrame
local SpawnButton = game:GetService("StarterGui").CarSpawner.SpawnCarButton
local RemoveButton = game:GetService("StarterGui").CarSpawner.RemoveCarButton
local Opened = false
PlayButton.MouseButton1Click:Connect(function()
if not Opened then
Opened = true
wait(1.5)
background:TweenPosition(UDim2.new(0.011, 0,0.741, 0),"InOut","Quint", 0.5, true)
SpawnButton:TweenPosition(UDim2.new(0.017, 0,0.756,0),"InOut","Quint", 0.5, true)
RemoveButton:TweenPosition(UDim2.new(0.016, 0,0.872,0),"InOut","Quint", 0.5, true)
for i = 0,10,1 do
wait()
end
end
end)