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

RemoteEvent function parameters, how to use them?

Hey guys, here I am, again, with another question about my Admin Panel;

I created a RemoteEvent called "gold", which will reset the target's gold when a specific TextButton is pressed. This is the code I'm using, but the Output is responding with: RegisteredCode is not a valid member of Players, even though, clearly, I am a member of Players.

Thanks to incapaz for most of this script

LOCALSCRIPT:

local target = script.Parent.Parent.user
local event = game.ReplicatedStorage.gold

function reset(user)
	event:FireServer(user)
end

script.Parent.MouseButton1Click:Connect(function()
	if game.Players:FindFirstChild(target.Text) then
		if not game.Players[target.Text]:IsA("Player") then return end
	   		reset(target.Text)
	    else
			print("Nope!")
	end
end)

SCRIPT:

game.Players.PlayerAdded:Connect(function(plr)
	local int = Instance.new("IntValue")
	int.Parent = plr
	int.Name = "gold"
	int.Value = 10
end)

local resetgold = game.ReplicatedStorage.gold

resetgold.OnServerEvent:Connect(function(player, user)
	game.Players(user).gold.Value = 0
end)

1 answer

✓ Accepted answer

Notice in line 11 of the Script how you're finding the user and how you also do it in line 10 of the local script. Indexing/finding a value is done by using squared brackets, "[ ]".

Instead of what you have in line 11 of the Script do:

game.Players[user].gold.Value = 0

You also have some tabbing hiccups in your local script. Might want to fix that.

2 comments

0

Thanks, didn't realize using [] was such a difference from ()! And where are the hiccups according to you? I honestly thought my tabbings were perfect

0

Lines 11-13 on the local script are tabbed once to the right. Line 10's if statement ends on the same line.

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