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

Attempt index with 'stats' in local script StarterGui?

Asked by
TechModel 118
3 years ago
Edited 3 years ago

This script is triggered by remote event and when it does, it sends the amount to the client. Notice that it cant get the client's stats and I do not know why. I'm trying to get the 'Stolen' stats and show it as definition on the text label in startergui made with frame by me. Output telling me it's happening at line 3 'local leaderstats = client.stats'

How to resolve this issue? Thanks

game.ReplicatedStorage.NoticeRecall.OnClientEvent:Connect(function(client)

    local leaderstats = client.stats
    local gold = leaderstats.Stolen

    local frame = script.Parent.Frame
    local text = frame.Label
    frame.Visible = true
    text.Text = "You received: "..gold
    wait(5)
    frame.Visible = false
end)

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

This happens because you probably didn't pass the player argument. There are 2 ways you can do this.

Solution 1

Fixed ServerScript:

game.ReplicatedStorage.NoticeRecall:FireClient(player, player)

The first argument is the player you want to fire the RemoteEvent to, and the 2, 3, 4, etc. are just arguments you want to pass which the 2nd is the player.

Note that the 1st argument isn't passed on to OnClientEvent.

Solution 2

Another way of doing this is not to pass a player argument, but to define the LocalPlayer in the LocalScript which I'd prefer.

ServerScript

game.ReplicatedStorage.NoticeRecall:FireClient(player)

LocalScript

local client = game.Players.LocalPlayer

game.ReplicatedStorage.NoticeRecall.OnClientEvent:Connect(function()

    local leaderstats = client.stats
    local gold = leaderstats.Stolen

    local frame = script.Parent.Frame
    local text = frame.Label
    frame.Visible = true
    text.Text = "You received: "..gold
    wait(5)
    frame.Visible = false
end)

You can see the :FireClient() parameters here.

0
Thank you so much for the help, but i really dont get why i need to pass the argument 2 times? TechModel 118 — 3y
Ad

Answer this question