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

Attempt index with 'stats' in local script StarterGui?

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

✓ Accepted answer

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.

1 comment

0

Thank you so much for the help, but i really dont get why i need to pass the argument 2 times?

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