Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I am haveing issues with my local script for my gui .... ?

I need help with this script! So I need help with this. I was trying to make something whare if you were to click a button it wouild check at your leaderstats and see if you have 900,000 "Car cash". Then you have it it will teleport you to somewhare if you don't it will clone a gui that says error then after 5 seccents it will close it. Please help as im geting errors and im not very good with this kind of scripting C:.

local plr = game.Players.LocalPlayer
local Gui = game.StarterGui.Error
script.Parent.MouseButton1Click:connect(function()
	if plr.leaderstats.CarCash.Value >= 900000 then
		game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-994.023, -11.5, 155.904))
	else
 Gui:Clone()
wait(5)
Gui:Destory()
end
		

1 answer

I'll help you, man!!!

What you want is this:

repeat wait() until game.Players.LocalPlayer --Fix a ROBLOX error.
repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerGui") --Fix another ROBLOX error :S
local plr = game.Players.LocalPlayer
local Gui = plr.PlayerGui.Error --When you click 'Play' the StarterGui changes location to PlayerGui, inside of the player, so I changed the path to the correct one.
script.Parent.MouseButton1Click:connect(function()
	if plr.leaderstats.CarCash.Value > 899999 then -->= and <= didn't work for me a couple of times, so instead, to make sure, I'll just use > and take off 1 value (> 899999)
		--Nope, that's not how you change player's position. game.Workspace.Player.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-994.023, -11.5, 155.904))
		plr.Character:MoveTo(Vector3.new(-994.023, -11.5, 155.904))
	else --Cloning in this case makes no sense... What you want is it to show... So, you'll get the frame or error message or whatever you have inside of that gui, and make its visible property to false. make the gui's enabled property to true. then, this will make sense.
		Gui.ErrorText.Visible = true --Change the ErrorText with the actual error text's name.
		wait(5)
		Gui.ErrorText.Visible = false --Once more, change the ErrorText with the actual error text's name.
end

This should work. But, to be honest, these are pretty easy things to do, and you didn't even know about the PlayerGui, so I suggest you take a deeper look about scripting, because what I saw here is that your scripting skills are pretty low. Here's a few links you might want to see:

PlayerGui; StarterGui; MoveTo; Visible; CFrame; Vector3 And there's even 2 similar things to CFrame and Vector3, called UDim2 and UDim: UDim2 UDim

Of course these are only optional things, but they would really improve your scripting if you got them right.

Having said that, if this works, please mark as the correct answer!

As always, good scripting!

This discussion is preserved as it was. New answers, comments, and votes are closed.