Can't get This to work

local cam = game.Workspace.CurrentCamera
local remote = game.ReplicatedStorage.Events.setvalue
local remote2 = game.ReplicatedStorage.Events.setvalue2

script.Parent.Parent.Parent.BottomButton.MouseButton1Click:connect(function()
	local clicked = false

	local LoadChar = game.ReplicatedStorage.Events:WaitForChild("LoadChar")

	local player = game.Players.LocalPlayer
	local Pos = player.Character:GetPrimaryPartCFrame()
	local currentCamera = workspace.CurrentCamera
if clicked == false then
		clicked = true


	remote:FireServer(player)
end
	if clicked == true then
		clicked = false
		LoadChar:FireServer()
		cam.CameraSubject = player.Character.Humanoid
		cam.CameraType = "Custom"
		cam.CFrame = player.Character.Head.CFrame
		end
end)

For some reason, when i click the button, it respawns my player, even though it says if clicked == false then
it literally isnt working, and i have no idea why. The value is set to false. Not true… what do i do?

1 Like

Are you trying to reload the players char everytime you press the button?( with conditions)

its because the script reads from top to down so it fires the if clicked == false then AND because you set condition to true in it the next if is also true.

EDIT: some showcase

local clicked =  false
if clicked == false then -- 1:check if false and it is
		clicked = true -- 2:changes it to true


	remote:FireServer(player)
end
	if clicked == true then -- 3:checks if true and because of 2 it is now true and fires
		clicked = false -- 4:sets it back to false
1 Like

Pretty much yeah, the remote event thats fired changes the players character model.

1 Like

You could shorten that by using else/elseif

Alright, its a different story now, if its R6, and you want to save it too for next reloading, I’d recommend using HumanoidDescription or an array containing items such as hats and shirts.

You need to check the if statements and see if everything works properly, dont forget to use else/elseif when needed, it can help alot.

see, Im not even to that point yet

for some reason. even with all the content commented out. it still fires the clicked == false remote when i click it twice, its like the variable never changes. and i have no idea why

local cam = game.Workspace.CurrentCamera
local remote = game.ReplicatedStorage.Events.setvalue
local remote2 = game.ReplicatedStorage.Events.setvalue2
local clicked = false
--local LoadChar = game.ReplicatedStorage.Events:WaitForChild("LoadChar")

local player = game.Players.LocalPlayer
local currentCamera = workspace.CurrentCamera

local name = player.Name
script.Parent.Parent.Parent.BottomButton.MouseButton1Click:connect(function()
	--local Pos = player.Character:GetPrimaryPartCFrame()


if clicked == false then
		remote:FireServer(player)
		clicked = true
		
	end
	if clicked == true then
	--	LoadChar:FireServer()
		--player.Character:SetPrimaryPartCFrame(Pos)
		--remote2:FireServer(player.Character)

		--LoadChar:FireServer()
		--cam.CameraSubject = player.Character.Humanoid
		--cam.CameraType = "Custom"
		--cam.CFrame = player.Character.Head.CFrame
		clicked = false
		
	end
end)

Change it to "If IsClicked == false then
IsClicked = true
else (when its true)
IsClicked = false
end

And move from here , best of luck!

	local cam = game.Workspace.CurrentCamera
	local remote = game.ReplicatedStorage.Events.setvalue
	local remote2 = game.ReplicatedStorage.Events.setvalue2
	local clicked = false
	--local LoadChar = game.ReplicatedStorage.Events:WaitForChild("LoadChar")

	local player = game.Players.LocalPlayer
	local currentCamera = workspace.CurrentCamera

	local name = player.Name
	script.Parent.Parent.Parent.BottomButton.MouseButton1Click:connect(function()
		--local Pos = player.Character:GetPrimaryPartCFrame()


	if clicked == false then
			remote:FireServer(player)
			clicked = true
			
		
		else 
		--	LoadChar:FireServer()
			--player.Character:SetPrimaryPartCFrame(Pos)
			--remote2:FireServer(player.Character)

			--LoadChar:FireServer()
			--cam.CameraSubject = player.Character.Humanoid
			--cam.CameraType = "Custom"
			--cam.CFrame = player.Character.Head.CFrame
			clicked = false
			
		end
	end)

Same result unfortunately


Here i clicked it three times

image
I have it set up to say bruh when i click it.

So if i clicked it 3 times, shouldnt it only say bruh twice?

You can add a debounce to prevent this occurrance, or just check if the player already pressed on it.

thats what the clicked local is, isnt it?

Added debounce, same result

Make another value( can be boolean,number etc…) and name it “Debounce”. Now, everytime you pressed the button, you should change the debounce value, wait a couple of secs, and turn it back. Not on pc currently, and its actually 3 AM for me, so I cant do much. But, I think you better use remoteFunction( u can return with it, and re- use it)

I will make a code with more explanation tomorrow.

try not to forget me lol, i apreciate the effort though!!

1 Like

Dont worry, ill return: good night

1 Like

fixed it, had to untick this box in a gui
image