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

Why is player being considered a number value?

I have a remote event that fires to the client and i'm trying to fire the player but for some reason the player is taking the role of the numberamnt

local box = script.Parent
local stat = game.ReplicatedStorage.Remote.StatUpd

local function PlayerTouched(Part)
	local Parent = Part.Parent
	if game.Players:GetPlayerFromCharacter(Parent) then
		local plr = game.Players[Parent.Name]
		local moneyamnt = math.random(200,400)	
		stat:FireClient(plr, moneyamnt)
	end
end

box.Touched:connect(PlayerTouched)

^^^ The script firing the client (Not a local script)

local stat = game.ReplicatedStorage.Remote.StatUpd

stat.OnClientEvent:Connect(function(plr, moneyamnt)
	plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + moneyamnt.Value
end)

^^^ The script receiving what the client fires

2 answers

###This is because of line 3 of your local script. You added a plr parameter. The OnClientEvent event doesn’t pass the player as a parameter. Remove it. Also, you shouldn’t be giving money through the client, as this gives the client power. Never trust the client.

stat.OnClientEvent.Connect(function(money)

###This should work.

3 comments

0

Well the reason I did this is because I can't seem to use onTouched in a LocalScript

0

You shouldn’t be.

0

use game.Players.LocalPlayer.leaderstats

plr is just a name, you need to do game.Players[plr].leaderstats etc, unless you can fire objects with fireclient which in that case just make plr = game.Players:GetPlayerFromCharacter(Parent). Not sure if possible. Also don't do moneyamnt.Value, moneyamnt is just a number.

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