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

How to get player name in remote event?

I got a tool that has this script in it:

script.Parent.Activated:Connect(function()
	game.ReplicatedStorage.ToolUseEvent:FireServer()
	wait(1)
end)

This tool lays in player's backpack by default.

And i got a server script:

game.ReplicatedStorage.ToolUseEvent.OnServerEvent:Connect(function(Player)
	local Soda = game.Players.Player.Backpack --here is the problem
	if Soda.RegularSoda then
		Player.leaderstats.Sugar.Value = Player.leaderstats.Sugar.Value + 1
	end
end)

I need to check if players has a tool called RegularSoda to give him sugar. That is some sort of anti exploiting.

1 answer

✓ Accepted answer
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local ToolUseEvent = ReplicatedStorage.ToolUseEvent


local function RaiseSugarUponConsumption(PlayerConsuming)
    if (Player.Backpack:FindFirstChild("RegularSoda"))
        ---------------
        Player.leaderstats.Sugar.Value += 1
    end
end


ToolUseEvent.OnServerEvent:Connect(RaiseSugarUponConsumption)

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