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

How to give cash to player that picked it up?

This is the cash script

local part = script.Parent
local cash = part.Parent.Money


part.Transparency = 1
part.Position = cash.Position

part.Touched:Connect(function(hit)
local player = hit.Parent
	if player:FindFirstChild("Humanoid").Health > 0 then
		if player.Name == game.Players.THIS_IS_THE_PROBLEM.Name then
			game.Players.THIS_IS_THE_PROBLEM.leaderstats.Cash.Value = game.Players.THIS_IS_THE_PROBLEM.leaderstats.Cash.Value +3
		end
	end

end)

I could just put my name there, but i need to somehow get the name of the player that touched hitbox from game.Players tab.

2 comments

0

Thx, that exactly what i was looking for

2 answers

✓ Accepted answer

A good way to do this is to use :GetPlayerFromCharacter. Learn more here: https://developer.roblox.com/en-us/api-reference/function/Players/GetPlayerFromCharacter

local moneyGain = 3

local part = script.Parent
local cash = part.Parent.Money

part.Transparency = 1
part.Position = cash.Position

part.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
	if player.Name == "Username" then
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + moneyGain
	end
end
end)
local part = script.Parent
local cash = part.Parent.Money


part.Transparency = 1
part.Position = cash.Position
cash = player.leaderstats.Cash

part.Touched:Connect(function(hit)
local player = hit.Parent
    if player:FindFirstChild("Humanoid").Health > 0 then
        if player.Name == "DenchikRus" then -- replace USER with your name
            DenchikRus.cash.Value = cash.Value +3
        end
    end

end)

3 comments

0

Wrong

0

lol

0

bruh i got answer from ForeverBrown, this is wrong

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