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

I made a script, but it does not seem to work, can anyone help me check if there is anything wrong?

I made this script,

it is called a handler, a script and it is inside of ServerScriptService

local Events = game:GetService("ReplicatedStorage").Events
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function getStat(plr, nameValue)
	return ReplicatedStorage.Stats:FindFirstChild(plr):FindFirstChild(nameValue).Value
end

Events.GetStat.OnServerInvoke = getStat() 

But when I test it, it gave me an error saying, " Argument 1 missing or nil"

Here are the script that is related to it this script is called a display, and it is a "local script" inside of a "frame"

local Events = game:GetService("ReplicatedStorage").Events

while wait(0.1) do
	local gvalue = Events.GetStat:InvokeServer("Grass")
	local limit = Events.GetStat:InvokeServer("Limit")
	
	script.Parent.LimitText.Text =  tostring(gvalue).."/".. tostring(limit) 
end

Can anyone help? Thanks!

5 comments

0

What happens when you remove the parenthesis from the "getStat" assignement so that it becomes "Events.GetStat.OnServerInvoke = getStat"

0

Note: I think there is a limit to how often you can invoke the server. Or if there isn't it will cause a lot of lag.

0

You would have to do plr.Name for :FindFirstChld to work

0

plr is an object

0

Don't use wait(0.1) as a condition. It's a hack.

2 answers

✓ Accepted answer

The issue is that you are calling the function on line 8. Instead you will want to just remove the parentheses and it should work. You are basically setting the Events.GetStat.OnServerInvoke equal to whatever the function returns when it runs. Instead just do:

Events.GetStat.OnServerInvoke = getStat

and you should be good to go. I hope this helps and have a great day scripting!

The problem is that you have tried to access an argument (nameValue) in your function getStat that doesn't exist.

You need to pass the value of nameValue when calling the function on line 8:

Events.GetStat.OnServerInvoke = getStat() -- pass the value of 'nameValue' in the parentheses.

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