I'm currently making a gun shop for my zombie game, but I've run into an issue.

I don't have any experience in remote events, so I was wondering if someone could help me.

This normal script is in ServerScriptService

--Variables--
local Button = script.Parent
local Player = game:GetService("Players").LocalPlayer
local RemoteEvent = game:GetService("ReplicatedStorage").BuyRemoteEvent
local PurchaseButton = script.Parent.BuyPrompt.PurchaseButton
local LeaveButton = script.Parent.BuyPrompt.LeaveButton

--Actual Scripting--
local RemoteEvent = game:GetService("ReplicatedStorage").BuyRemoteEvent
local Item = game:GetService("ServerStorage").Guns.FourthGun
RemoteEvent.OnServerEvent:Connect(function(Player, item)
	if item == Item.Name then
		local Cash = Player.leaderstats.Cash
		if Cash.Value >= 50 then
			Cash.Value = Cash.Value - 50
			Item = Item:Clone()
			Item.Parent = Player.Backpack
			else
			print("Not enough cash")
		end
	end
end)

This local Script is somewhere deep in StarterGUI

--Variables--
local Button = script.Parent
local Player = game:GetService("Players").LocalPlayer
local RemoteEvent = game:GetService("ReplicatedStorage").BuyRemoteEvent
local PurchaseButton = script.Parent.BuyPrompt.PurchaseButton
local LeaveButton = script.Parent.BuyPrompt.LeaveButton

--Actual Scripting--
script.Parent.MouseButton1Down:Connect(function()
	script.Parent.BuyPrompt.Visible = true
end)

LeaveButton.MouseButton1Down:Connect(function()
	script.Parent.BuyPrompt.Visible = false
end)

PurchaseButton.MouseButton1Down:Connect(function()
	RemoteEvent:FireServer("FourthGun")
end)

6 comments

0

What do you need help with? https://idownvotedbecau.se/unclear

0

I need help with remote events overall

0

Like, do i put it all in one script or in two scripts like that?

0

Two scripts like that

0

But for some reason it doesn't work, do you know why?

0

What do you mean "doesn't work"? http://xyproblem.info