I need your help community

So, in 30 days is my best friend birthday, and I want to make a surprise to him, I want to create a game that he always wanted to play, but the game don’t existed, but there’s a problem, I just know the very very very basic of programming in roblox, so i need your help guys

I already created this script in ServerScriptServer to make the currency that will exist in the game
image
image

But I want to make a script that when I hit a specific part with a tool in the map it gives me money (TIX in the case) and if I hit this part with a different tool it gives me more money than the first tool.

2 Likes

You could write a script like this and put it in whatever part you want to give the money:

local part = workspace.Part --Your part
local debounce = false
part.Touched:Connect(function(touch)
    if touch.Name == "Handle" and touch.Parent.Name == "NameOfToolHere" then
        if debounce == false then
            debounce = true
            --From here, you can put a RemoteEvent in your script that's in
            --ServerScriptService that gives the player money and fire it
            --from inside this statement
            wait(1)
            debounce = false --A debounce can be used to give your part a cooldown
        end
    end
end)
2 Likes

To answer his script in the brackets you could do:
player.leaderstats.TIX.Value = player.leaderstats.TIX.Value + 100

2 Likes

You could use the .Touched function for the part and check if the object that touched the part is the tool that you’re looking for; like this:

local part = script.Parent

part.Touched:Connect(function(hit)
    
    if hit.Parent.Name == "your tool name here" then

        -- do stuff

    end

end)

To get the player’s leaderstats I’d like to recommend doing this:

if hit.Parent:FindFirstChild("HumanoidRootPart") then -- real player

    local stats = game.Players[hit.Parent.Name]:WaitForChild("leaderstats")
    local Currency = stats.TIX

    Currency.Value = Currency.Value + 50 -- custom value

end
1 Like

You don’t need the stats variable, just do player.leaderstats.TIX.Value = player.leaderstats.TIX.Value + 100.

2 Likes

Adding on here, you can shorten the code quite significantly by using a compound operator:

player.leaderstats.TIX.Value += 100

So something like this to increment currency should suffice.

local Players = game:GetService("Players")

. . .

part.Touched:Connect(function(hit)
    local player = Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        player.leaderstats.TIX.Value += 100
    end
end)
1 Like