How to change the value through a script

Hi, I have a local script in my game in which I would like to a part to increase/decrease a player’s value also the value is located in StarterPlayer>StarterPlayerScripts and I’m trying to make a GUI that increases/decrease after pressing the button, the value inside the StarterPlayerScripts.

Provide the script you have so we can assist you.

1 Like

I just hope you at least tried to do it before posting this. Anyways here’s the basic template:

--The local script should be under the GUI button for the code below to work
local player = game.Players.LocalPlayer
local scripts = player:WaitForChild("PlayerScripts")
script.Parent.MouseButton1Click:Connect(function()
   scripts.EValue.Value += 0 --Change EValue to the name of the value and 0 to the increment to increase
end)

If you want it to decrease value you just change += to -=

And if you want it to either increase or decrease you could do this:

--The local script should be under the GUI button for the code below to work
local player = game.Players.LocalPlayer
local scripts = player:WaitForChild("PlayerScripts")
script.Parent.MouseButton1Click:Connect(function()
   local randomNo = math.random(1, 2)
   if randomNo == 1 then
      scripts.EValue.Value += 0 --Change EValue to the name of the value and 0 to the increment to increase
   else
      scripts.EValue.Value -= 0 --As I said earlier, change 0 to the value you want to decrease by
   end
end)

There.

3 Likes

Menu script: restartime doesn’t do anything

local Menu = script.Parent.MenuFrame
local ShopButton = Menu.ShopButtonFrame.Button
local SettingsButton = Menu.SettingsButtonFrame.Button
local HelpButton = Menu.HelpButtonFrame.Button
local MenuButton = script.Parent.MenuButtonFrame.TextButton
local BackButton = Menu.ExitButton
local CurrentFrame = "None"


BackButton.MouseButton1Click:Connect(function()
	if CurrentFrame == "Main" then
		CurrentFrame = "None"
		Menu.Visible = false
		Menu.ShopButtonFrame.Visible = true
		Menu.HelpButtonFrame.Visible = true
		Menu.SettingsButtonFrame.Visible = true
	elseif CurrentFrame == "ShopMenu" or CurrentFrame == "HelpMenu" or CurrentFrame == "SettingsMenu" then
		CurrentFrame = "Main"
		Menu.Visible = true
		Menu.ShopButtonFrame.Visible = true
		Menu.HelpButtonFrame.Visible = true
		Menu.SettingsButtonFrame.Visible = true
		Menu.ShopMenu.Visible = false
		Menu.SettingsMenu.Visible = false
		Menu.HelpMenu.Visible = false
	end
end)

script.Parent.MenuButtonFrame.TextButton.MouseButton1Click:Connect(function()
	if CurrentFrame == "Main" then
		CurrentFrame = "None"
		Menu.Visible = false
	elseif CurrentFrame == "None" then
		CurrentFrame = "Main"
		Menu.Visible = true
	end
end)

ShopButton.MouseButton1Click:Connect(function()
	CurrentFrame = "ShopMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = false
	Menu.HelpMenu.Visible = false
	Menu.ShopMenu.Visible = true
end)

HelpButton.MouseButton1Click:Connect(function()
	CurrentFrame = "HelpMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = false
	Menu.HelpMenu.Visible = true
	Menu.ShopMenu.Visible = false
end)

SettingsButton.MouseButton1Click:Connect(function()
	CurrentFrame = "SettingsMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = true
	Menu.HelpMenu.Visible = false
	Menu.ShopMenu.Visible = false
end)


_G.RestartTime=3

function UpdateQRSpeedButton()
	local v=_G.RestartTime
	if v~=0 then
		Menu.SettingsMenu.QuickResetSpeed.QRSpeed.Text=(tostring(v)..' Second'..(v==1 and '' or 's'))
	else
		Menu.SettingsMenu.QuickResetSpeed.QRSpeed.Text='Instant'
	end
end
UpdateQRSpeedButton()
Menu.SettingsMenu.QuickResetSpeed.QRSpeed.MouseButton1Click:Connect(function()
	if _G.RestartTime<10 then
		_G.RestartTime=_G.RestartTime+1
	end
	UpdateQRSpeedButton()
end)
Menu.SettingsMenu.QuickResetSpeed.QRSpeed.MouseButton2Click:Connect(function()
	if _G.RestartTime>0 then
		_G.RestartTime=_G.RestartTime-1
	end
	UpdateQRSpeedButton()
end)

Do you see any errors in console?

nope i dont see any errors in console

Do you know exactly where the problem occurs?

1 Like

im pretty sure its on menu script

local Menu = script.Parent:WaitForChild("MenuFrame")
local ShopButton = Menu:WaitForChild("ShopButtonFrame"):WaitForChild("Button")
local SettingsButton = Menu:WaitForChild("SettingsButtonFrame"):WaitForChild("Button")
local HelpButton = Menu:WaitForChild("HelpButtonFrame"):WaitForChild("Button")
local MenuButton = script.Parent:WaitForChild("MenuButtonFrame"):WaitForChild("TextButton")
local BackButton = Menu:WaitForChild("ExitButton")
local CurrentFrame = "None"


BackButton.MouseButton1Click:Connect(function()
	if CurrentFrame == "Main" then
		CurrentFrame = "None"
		Menu.Visible = false
		Menu.ShopButtonFrame.Visible = true
		Menu.HelpButtonFrame.Visible = true
		Menu.SettingsButtonFrame.Visible = true
	elseif CurrentFrame == "ShopMenu" or CurrentFrame == "HelpMenu" or CurrentFrame == "SettingsMenu" then
		CurrentFrame = "Main"
		Menu.Visible = true
		Menu.ShopButtonFrame.Visible = true
		Menu.HelpButtonFrame.Visible = true
		Menu.SettingsButtonFrame.Visible = true
		Menu.ShopMenu.Visible = false
		Menu.SettingsMenu.Visible = false
		Menu.HelpMenu.Visible = false
	end
end)

script.Parent.MenuButtonFrame.TextButton.MouseButton1Click:Connect(function()
	if CurrentFrame == "Main" then
		CurrentFrame = "None"
		Menu.Visible = false
	elseif CurrentFrame == "None" then
		CurrentFrame = "Main"
		Menu.Visible = true
	end
end)

ShopButton.MouseButton1Click:Connect(function()
	CurrentFrame = "ShopMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = false
	Menu.HelpMenu.Visible = false
	Menu.ShopMenu.Visible = true
end)

HelpButton.MouseButton1Click:Connect(function()
	CurrentFrame = "HelpMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = false
	Menu.HelpMenu.Visible = true
	Menu.ShopMenu.Visible = false
end)

SettingsButton.MouseButton1Click:Connect(function()
	CurrentFrame = "SettingsMenu"
	Menu.ShopButtonFrame.Visible = false
	Menu.HelpButtonFrame.Visible = false
	Menu.SettingsButtonFrame.Visible = false
	Menu.SettingsMenu.Visible = true
	Menu.HelpMenu.Visible = false
	Menu.ShopMenu.Visible = false
end)


local RestartTime=3
local qrSpeed = Menu:WaitForChild("SettingsMenu"):WaitForChild("QuickResetSpeed"):WaitForChild("QRSpeed")

function UpdateQRSpeedButton()
	local v=RestartTime
	if v~=0 then
		qrSpeed.Text=(tostring(v)..' Second'..(v==1 and '' or 's'))
	else
		qrSpeed.Text='Instant'
	end
end
UpdateQRSpeedButton()
qrSpeed.MouseButton1Click:Connect(function()
	if RestartTime<10 then
		RestartTime=RestartTime+1
	end
	UpdateQRSpeedButton()
end)
qrSpeed.MouseButton2Click:Connect(function()
	if RestartTime>0 then
		RestartTime=RestartTime-1
	end
	UpdateQRSpeedButton()
end)