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

Why is player being considered a number value?

Asked by 5 years ago

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

Log in to vote
1
Answered by 5 years ago

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.

0
Well the reason I did this is because I can't seem to use onTouched in a LocalScript VeryDarkDev 47 — 5y
0
You shouldn’t be. User#19524 175 — 5y
0
use game.Players.LocalPlayer.leaderstats the8bitdude11 358 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Answer this question