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

How To Make Dropped Cash Only Can Claimed By Other Player?

Asked by 1 year ago

Sorry For Bad English, I Am Making Script That When You Triggered Prompt, You Will Get Billboard Gui With "Wanted" Text On Head, And Need To Hide Until 100 Seconds Pass To Get Money, And If You Dies, You Drop The Money That You Got From Robbery, And Other Player Can Claim It But Problem Is That I Can Claim It too, And I Want Only Other Player Can Claim It, Can Someone Advice Me?, I'm Begginer To Scripting!

Cash Script

local money = script.Parent.Parent
local clickDetector = money.ClickDetector

clickDetector.MouseClick:Connect(function(plr)

    local cash = plr.leaderstats.Gold
    local amountValue = money.BillboardGui.amountOfCash 
    cash.Value += amountValue.Value

    money:Destroy()


end)

Proximity Prompt Script

local db = true
local script1 = game.Lighting.RobberyCashDrop.CashDrop
local gui = game.Lighting.RobberyCashDrop.WantedGUI

script.Parent.Triggered:Connect(function(plr)
    local Character = plr.Character or plr.CharacterAdded:Wait()
    if db == true then
        db = false
        local a = script1:Clone()
        a.Parent = Character
        local b = gui:Clone()
        b.Parent = Character:FindFirstChild("Head")
        wait(100)
        plr.leaderstats.Gold.Value = plr.leaderstats.Gold.Value + 250
        a:Destroy()
        b:Destroy()
        db = true
    else
        if plr.PlayerGui:FindFirstChild("NoMoneyPrompt") then
            plr.PlayerGui:FindFirstChild("NoMoneyPrompt"):Destroy()
            local errorprompt = game.ReplicatedStorage.RobberyGUI.NoMoneyPrompt:Clone()
            errorprompt.Parent = plr.PlayerGui
            wait(1)
            errorprompt:Destroy()
        else
            local errorprompt = game.ReplicatedStorage.RobberyGUI.NoMoneyPrompt:Clone()
            errorprompt.Parent = plr.PlayerGui
            wait(1)
            errorprompt:Destroy()
        end

    end
end)

Cash Drop Script

local char = script.Parent 
local human = char:WaitForChild("Humanoid")
local humanRoot = char:WaitForChild("HumanoidRootPart")
local cash = game.Lighting.RobberyCashDrop:WaitForChild("Cash")
local PlayerService = game:GetService("Players")

human.Died:Connect(function() 
    local playerFromCharacter = PlayerService:GetPlayerFromCharacter(human.Parent)
    local moneyDropped = 250
    local cashClone = cash:Clone() 
    cashClone.BillboardGui.amountOfCash.Value = moneyDropped 
    cashClone.BillboardGui.amount.Text = "$" .. tostring(moneyDropped) 

    cashClone.Parent = game.Workspace 

    cashClone.CFrame = humanRoot.CFrame + (humanRoot.CFrame.LookVector * Vector3.new(2,2,2))
end)

1 answer

Log in to vote
1
Answered by 1 year ago

You just make an int value that holds the user id so that you can check who the owner is.

Drop Cash Script:

local char = script.Parent 
local human = char:WaitForChild("Humanoid")
local humanRoot = char:WaitForChild("HumanoidRootPart")
local cash = game.Lighting.RobberyCashDrop:WaitForChild("Cash")
local PlayerService = game:GetService("Players")

human.Died:Connect(function()
    local playerFromCharacter = PlayerService:GetPlayerFromCharacter(human.Parent)
    local moneyDropped = 250
    local cashClone = cash:Clone() 
    cashClone.BillboardGui.amountOfCash.Value = moneyDropped 
    cashClone.BillboardGui.amount.Text = "$" .. tostring(moneyDropped)


    local val = Instance.new("IntValue")
    val.Parent = cashClone
    val.Value = playerFromCharacter.UserId

    cashClone.Parent = game.Workspace 

    cashClone.CFrame = humanRoot.CFrame + (humanRoot.CFrame.LookVector * Vector3.new(2,2,2))
end)

Cash Script:

local money = script.Parent.Parent
local clickDetector = money.ClickDetector

clickDetector.MouseClick:Connect(function(plr)
    if plr.UserId ~= money.IntValue.Value then
    local cash = plr.leaderstats.Gold
    local amountValue = money.BillboardGui.amountOfCash 
    cash.Value += amountValue.Value

    money:Destroy()
    end

end)

Hope you understand what I did and I hope that this helps :)

0
Name the IntValue too in case if there are two or more children named "IntValue" in cashClone T3_MasterGamer 2189 — 1y
Ad

Answer this question