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

How to give cash to player that picked it up?

Asked by 4 years ago
Edited 4 years ago

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.

0
Thx, that exactly what i was looking for DenchikRus 0 — 4y

2 answers

Log in to vote
0
Answered by
Lucke0051 165
4 years ago

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)
Ad
Log in to vote
0
Answered by
3wdo 198
4 years ago
Edited 4 years ago
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)
0
Wrong Spjureeedd 385 — 4y
0
lol ForeverBrown 356 — 4y
0
bruh i got answer from ForeverBrown, this is wrong DenchikRus 0 — 4y

Answer this question