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

Bindable event not working correctly for shop gui?

--What I want is when the event is fired it will make a clone of the gui and put it in the players playergui but not even the function called when the event is fired will work. please help--

Server:

local remote = game.ReplicatedStorage.Remotes.pp
local this = script.Parent




this.CD.MouseClick:Connect(function(plrc)
	remote:FireClient(plrc,"EmeraldAxe")
end)


Local:

local remote = script.Parent.pp
local stats = game.ReplicatedStorage.Axestats
local hasgui = false
local lplr = game.Players.LocalPlayer



local function makegui(plr1,axe,price)
	print("function started")
	local gui = game.ReplicatedStorage.PurchaseGUI
	local ngui = gui:Clone()
	ngui.Parent = lplr.PlayerGui
	ngui.f1.bl1.Text = ("Buy" .. axe .. "for" .. " $" .. price .. "?")
end

remote.OnClientEvent:Connect(function(plr,axe)
	
	print("remote fired")
	if axe == "EmeraldAxe" then
		print("emerald fired")
		hasgui = true
		local ap = stats.EmeraldAxe.Price
		makegui(plr,axe,ap)
end
end)


1 comment

0

use a remote event instead of a bindable

2 answers

✓ Accepted answer

###The OnClientEvent event does not pass the player as a parameter by default, only OnServerEvent does this. You do need the Player argument in FireClient, but the player parameter in OnClientEvent is unnecessary.

local remote = script.Parent.pp
local stats = game.ReplicatedStorage.Axestats
local hasgui = false
local lplr = game.Players.LocalPlayer



local function makegui(axe,price)
    print("function started")
    local gui = game.ReplicatedStorage.PurchaseGUI
    local ngui = gui:Clone()
    ngui.Parent = lplr.PlayerGui
    ngui.f1.bl1.Text = "Buy " .. axe .. "for $" .. price.Value.. "?" -- brackets irrelevant
end

remote.OnClientEvent:Connect(function(axe)
    print("remote fired")

    if axe == "EmeraldAxe" then
        print("emerald fired")
        hasgui = true
        local ap = stats.EmeraldAxe.Price
        makegui(axe,ap)
    end
end)
-- back in the server
local remote = game.ReplicatedStorage.Remotes.pp
local this = script.Parent




this.CD.MouseClick:Connect(function(plrc)
    remote:FireClient(plrc,"EmeraldAxe", 50) -- I just put 50, but you need a number or else your arguments are nil 
end)



This might help get you started as far as layout...

-- LocalScript 
local remote = game:GetService("ReplicatedStorage").YourGui -- name it


remote.OnClientEvent:Connect(function()
    script.Parent.Visible = true
end)

-- Server
local remote = game:GetService("ReplicatedStorage").YourGui

local function click(player) 
  remote:FireClient(player) -- fire to client
end 

script.Parent.ClickDetector.MouseClick:Connect(click)

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