Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why won't my remote event fire?

Asked by 4 years ago

I am trying to make a store and the remote event to buy the item won't fire. The LocalScript is:

local market = game:GetService("MarketplaceService")

game.ReplicatedStorage.thing.OnClientEvent:Connect(function()
    if market:PlayerOwnsAsset(game.Players.LocalPlayer,script.Parent.assetid.Value) then
        script.Parent.NameAndPrice.Text.Text = "You already have this item."
        script.Parent.ClickDetector:Destroy()
        return "1"
    else
        return "0"  
    end
end)

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(text)
    script.Parent.NameAndPrice.Text.Text = text
end)

game.ReplicatedStorage.comple.OnClientEvent:Connect(function()
    script.Parent.NameAndPrice.Text.Text = "You already have this item."
    script.Parent.ClickDetector:Destroy()
end)

game.ReplicatedStorage.err.OnClientEvent:Connect(function(text)
    script.Parent.NameAndPrice.Text.Text = "There was an error buying your item or you pressed cancel."
    wait(2)
    script.Parent.NameAndPrice.Text.Text = text
end)

game.ReplicatedStorage.buy.OnClientEvent:Connect(function()
    print("fire")
    market:PromptPurchase(game.Players.LocalPlayer,script.Parent.assetid.Value)
end)

And the regular script is:

market = game:GetService("MarketplaceService") -- gets the service so we can make the plr to buy our items
local hasitem -- makes sure the player doesnt have the item already
asset = game.Workspace.buyitem5035406672.assetid -- gives us a shortcut

game.Workspace.buyitem5035406672.ClickDetector.MouseClick:Connect(function(plr) -- when player clicks/taps
    if market:PlayerOwnsAsset(plr,asset.Value) then
        game.ReplicatedStorage.comple:FireClient(plr)
    else
        hasitem = "0"
    end
    if hasitem == "0" then
        game.ReplicatedStorage.RemoteEvent:FireClient(plr,"Processing..") -- makes the player know that it works
        print("hell")
        game.ReplicatedStorage.buy:FireClient(plr)
        market.PromptPurchaseFinished:Connect(function(plr,assetid,ispur)
            if plr == plr then
                if assetid == asset.Value then
                    if ispur == true then
                        game.ReplicatedStorage.comple:FireClient(plr)
                    elseif ispur == false then
                        game.ReplicatedStorage.err:FireClient(plr,"Buy Orange Best Shirt for 5 robux?")
                    end
                end
            end
        end)
    end
end)

Thanks!

Answer this question