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

Is there a way for me to edit text from a RemoteFunction on a Local script?

Asked by 4 years ago

I am trying to create a Notification like system. Where say a player buys an item, a simple text pops up on screen for 3 seconds, then destroys it self.

I have the notification working fine, whenever I buy an item I get the notification to pop up and leave perfectly fine, as well as having multiple at the same time. The main issue however is the text itself.

The way my game handles purchases in the shop, is it has your selected item, and the amount you buy. Whenever you click buy, it invokes the server to subtract cash and add the item. The problem is that the variables used to track the amount bought and the name of the item is in the local script, while my Remote Function scripting is server side.

The Remote Functions scripting clones an existing template, puts it in the visible frame, and then deletes it later. I can edit the text from the server, but not from the client, where I can use those variables.

Is there a way for me to

A. Share the variables between the server and client, so I can get the name and amount of the item bought,

OR

B. Edit the text in the client after it has been made, so that the variables won't be an issue.

Here is the script for the Remote Function and Shop bits.

game.ReplicatedStorage.Remotes:WaitForChild("Notification").OnServerInvoke = function(player, art, shop, box, award)
    local inv = player.Inventory
    local notif = player.PlayerGui.UserInterface.Notifs
    local holder = notif.NotifHolder
    local template = notif.Template

    if art == "shop" then
        local text = template:Clone()
        text.Parent = holder
        text.Visible = true
        wait(1)
        text:Destroy()
    end
end

and

                if PlayerMoney.Value >= (selectedItemShop.Cost.Value * BuyAmount) then
                    Remotes.ShopFunction:InvokeServer("Purchase", selectedItemShop.Name, BuyAmount)
                    BuyBTN.Text = "Success!"
                    workspace.Sounds.Buy:Play()
                    Remotes.Notification:InvokeServer("shop")
                    BuyBTN.Text = "Buy".." - $"..MathModule:GetSuffix((selectedItemShop.Cost.Value * BuyAmount))

1 answer

Log in to vote
0
Answered by
NotedAPI 810 Moderation Voter
4 years ago

Instead of using a RemoteFunction to make the notification appear you could probably control that in the LocalScript.Remove line 5 in the LocalScript and replace with what you put in the script for the notification.

local notif = player.PlayerGui.UserInterface.Notifs
local template = notif.Template


if PlayerMoney.Value >= (selectedItemShop.Cost.Value * BuyAmount) then
    Remotes.ShopFunction:InvokeServer("Purchase", selectedItemShop.Name, BuyAmount)
    BuyBTN.Text = "Success!"
    workspace.Sounds.Buy:Play()

    local text = template:Clone()
    text.Parent = holder
    text.Visible = true
    wait(1)       
    text:Destroy()

    BuyBTN.Text = "Buy".." - $"..MathModule:GetSuffix((selectedItemShop.Cost.Value * BuyAmount))

Let me know if this works

0
This worked! And since all of my notifications are going into the same Frame, it doesnt matter if they are made from different scripts! YourBoiKdude 2 — 4y
0
I'm glad I could help you! NotedAPI 810 — 4y
Ad

Answer this question