Gui visable = true

Make sure to actually explain to the person what you changed. I found the problem as soon as I viewed this. The problem was he put an else statement in the wrong spot.

1 Like

It isn’t works. I copied your script

local replicatedstorage = game.ReplicatedStorage
local AK47 = replicatedstorage["AK-47"]
local Pistol = replicatedstorage.Pistol
local SMG = replicatedstorage.SMG
local Shotgun = replicatedstorage.Shotgun


local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Money.Value >= 200 then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - 200
		local number = math.random(1,4)
		print(number)
		if number == 1 then
			local gun = AK47:Clone()
			gun.Parent = player.Backpack
		end
		if number == 2 then
			local gun = Pistol:Clone()
			gun.Parent = player.Backpack
		end
		if number == 3 then
			local gun = SMG:Clone()
			gun.Parent = player.Backpack
		end
		if number == 4 then
			local gun = Shotgun:Clone()
			gun.Parent = player.Backpack
		end
	else
		if player.leaderstats.Money.Value < 200 then
		player:WaitForChild("PlayerGui").TeamChange.Panel.Visible = true
	end
end
end)

It works, but only the first time

Can you please elaborate more? Try printing after if and elseif statement that is checking if the value is higher or lower, send me output I don’t really see any problems with your script.

Make sure to copy the script entirely you just did

else 
if

instead of

elseif 

so you are missing one end
if you do:

else
if

Edit can you show us the script in editor?

Is there a close button in the panel or something? What is the problem?

Yes. panel have a close button

No, this panel is a menu for buying money.

local replicatedstorage = game.ReplicatedStorage
local AK47 = replicatedstorage["AK-47"]
local Pistol = replicatedstorage.Pistol
local SMG = replicatedstorage.SMG
local Shotgun = replicatedstorage.Shotgun


local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Money.Value >= 200 then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - 200
		local number = math.random(1,4)
		print(number)
		if number == 1 then
			local gun = AK47:Clone()
			gun.Parent = player.Backpack
		end
		if number == 2 then
			local gun = Pistol:Clone()
			gun.Parent = player.Backpack
		end
		if number == 3 then
			local gun = SMG:Clone()
			gun.Parent = player.Backpack
		end
		if number == 4 then
			local gun = Shotgun:Clone()
			gun.Parent = player.Backpack
            end
	elseif player.leaderstats.Money.Value < 200 then
			player:WaitForChild("PlayerGui").TeamChange.Panel.Visible = true
	end
end)

Edit it like this.

Seems like you had more ends then it should be there.

But what is the problem???

This only works the first time. After I close the panel with the button, it no longer opens

Because you are handling this on Server, this will cause confusion between client and server.

The script should be the Same class example: If ProximityPrompt Script is Server Script then close button should be Server Script

If ProximityPrompt Script is already a Server Script then keep it like that; change the close panel script to Server Script.

1 Like

Add a print that checks the players value after the “If then” line. I think the problem with you is that you don’t have less than 200 money so the gui doesn’t becomes visible.

yes. i using local script to close it

Copy the LocalScript code and then delete LocalScript and create Server Script, where LocalScript was, and paste the copied code into Server Script.

!!! You need to add RemoteEvent to ReplicatedStorage !!!

Script:

local replicatedstorage = game.ReplicatedStorage
local AK47 = replicatedstorage["AK-47"]
local Pistol = replicatedstorage.Pistol
local SMG = replicatedstorage.SMG
local Shotgun = replicatedstorage.Shotgun

local RemoteEvent = replicatedstorage:WaitForChild("RemoteEvent") 

local ProximityPrompt = script.Parent

ProximityPrompt.Triggered:Connect(function(player)
	if player.leaderstats.Money.Value >= 200 then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - 200
		local number = math.random(1,4)
		print(number)
		if number == 1 then
			local gun = AK47:Clone()
			gun.Parent = player.Backpack
		end
		if number == 2 then
			local gun = Pistol:Clone()
			gun.Parent = player.Backpack
		end
		if number == 3 then
			local gun = SMG:Clone()
			gun.Parent = player.Backpack
		end
		if number == 4 then
			local gun = Shotgun:Clone()
			gun.Parent = player.Backpack
            end
	elseif player.leaderstats.Money.Value < 200 then
		RemoteEvent:FireClient(player)
	end
end)

Local script:

local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent") 
local player = game.Players.LocalPlayer

RemoteEvent.OnClientEvent:Connect(function() 
player:WaitForChild("PlayerGui").TeamChange.Panel.Visible = true
end) 

You don’t need a RemoteEvent. lol. Just change the LocalScript to ServerScript, so it receives the same data.

The problem was, the server detected that the Panel was still visible, but the client did not.

why so much effort if this also works well with the server script?

I prefer to do it like that, if them would like to change it lets do it.
I just sent example how this can be achieved.

Also Changing PlayerGui on server is not good practice.

Just change the Panel Close Script to a Server Script with the same code, from when it was a LocalScript.