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

How do I make a text label change with local script?

Asked by
MediaHQ 53
3 years ago
Edited 3 years ago

Alright so I am making a paycheck script and I am making it so it pops up with a notification that you received the money. The paycheck depends on the player's team. But instead of showing the money a player received, it shows 0. How do I fix this? My code (Local):

local MoneyValue = workspace.Leaderboard.PayCheck.Value

script.Parent.Text = "You've Received $"..MoneyValue --Updates the money with value doesn't work

while wait(60) do
    script.Sound.Playing = true
    script.Sound.Looped = false
    script.Parent.Parent.Visible = true
    wait(5)
    script.Sound.Playing = false
    script.Parent.Parent.Visible = false
end

It still gives the money to the player but I want this to show the money the player has received Edit 1: After changing teams it will show the money a player has gotten but from the last team Leaderboard Script (Just in case):

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:Connect(function(plr) -- Capital 'C'
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local cash = Instance.new("IntValue", folder)
    cash.Name = "Money"

    cash.Value = ds1:GetAsync(plr.UserId) or 500
    ds1:SetAsync(plr.UserId, cash.Value)

    cash.Changed:connect(function()
        ds1:SetAsync(plr.UserId, cash.Value)
    end)

    local function PayCheck() -- Creating a function
        local paycheck = script.PayCheck
        local teams = game:GetService("Teams")

        local payCheckTable = {
            ["Citizen"] = 120,
            ["Criminal"] = 150,
            ["Inmate"] = 0,
            ["Police"] = 200,
            ["HeavyGunDealer"] = 225,
            ["GunDealer"] = 165,
            ["AdminOnDuty"] = 10000     
        }

        for i, v in pairs(payCheckTable) do
            if plr.Team == teams[i] then
                paycheck.Value = v
            end
        end
    end

    while wait(55) do
        PayCheck() -- Triggers our function
        cash.Value = cash.Value + script.PayCheck.Value
    end
end)
--Thanks BestCreativeBoy
0
I have a similar problem to this, I can't can't get my text GUI to change when your player dies........ astonplep 32 — 3y
0
cant you get the leaderstats from the player? BeyondTheEgde 0 — 3y
0
also i think using a local script might be unnecessary BeyondTheEgde 0 — 3y

1 answer

Log in to vote
0
Answered by
sleazel 1287 Moderation Voter
3 years ago
Edited 3 years ago

As far as I understand, you are working very hard to avoid using RemoteEvents. While this might work, it is going to be a nightmare to synchronize properly. Making shenanigans like this sooner or later turn your scripts into a spaghetti code.

While your script could be fixed, I will update it to use RemoteEvent anyway. It would break for example when two players join at the same time. No more excuses, you need to start using Remotes, or you will never make a fully functional game.

Local Script:

local PayCheckEvent = game.ReplicatedStorage:WaitForChild("PayCheckEvent")

local function OnPayCheckEvent(amount)
   script.Parent.Text = "You've Received $" .. amount
    script.Sound.Playing = true
    script.Sound.Looped = false
    script.Parent.Parent.Visible = true
    wait(5)
    script.Sound.Playing = false
    script.Parent.Parent.Visible = false

end
PayCheckEvent.OnClientEvent:Connect(OnPayCheckEvent)

ServerScript:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("CashSaveSystem")

local PayCheckEvent = Instance.new("RemoteEvent")
PayCheckEvent.Name = "PayCheckEvent"
PayCheckEvent.Parent = game.ReplicatedStorage



game.Players.PlayerAdded:Connect(function(plr) -- Capital 'C'
    local folder = Instance.new("Folder", plr)
    folder.Name = "leaderstats"
    local cash = Instance.new("IntValue", folder)
    cash.Name = "Money"

    cash.Value = ds1:GetAsync(plr.UserId) or 500
    ds1:SetAsync(plr.UserId, cash.Value)

    cash.Changed:connect(function()
        ds1:SetAsync(plr.UserId, cash.Value)
    end)

    local function PayCheck() -- Creating a function
        local teams = game:GetService("Teams")

        local payCheckTable = {
            ["Citizen"] = 120,
            ["Criminal"] = 150,
            ["Inmate"] = 0,
            ["Police"] = 200,
            ["HeavyGunDealer"] = 225,
            ["GunDealer"] = 165,
            ["AdminOnDuty"] = 10000     
        }

        for i, v in pairs(payCheckTable) do
            if plr.Team == teams[i] then
                return v
            end
        end
    end

    while wait(55) and plr.Parent == game.Players do --player may have left the game
        local paycheck = PayCheck() -- Triggers our function
        cash.Value = cash.Value + paycheck
    PayCheckEvent:FireClient(plr,paycheck) --fire client
    end
end)

Hope this helps. Edit: I changed player to plr in server script.

0
I avoid remotefunctions because they really hard to understand MediaHQ 53 — 3y
Ad

Answer this question