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

how to make if part touched and give money?


local teleportModule = require(game.ServerScriptService.TeleportModule)

local doorModel = script.Parent
local door = doorModel.Door
local destination = doorModel.Destination
local givescript = doorModel.Money

deBounce = false
waitDelay = 1

door.Touched:Connect(function(hit)
	if deBounce == false then
		deBounce = true 
		-- Get Character
		local character = hit.Parent
		-- Check if Character and Humanoid Health > 0
		if character:FindFirstChild("Humanoid") and character:FindFirstChild("Humanoid").Health > 0 then
			local player = game.Players:GetPlayerFromCharacter(character)
			teleportModule.teleportPlayer(player, destination) -- Trigger Module
			game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 100
		end
		wait(waitDelay)
		deBounce = false
	end
end)

givescript.Disabled = false
wait(3)
givescript.Disabled = true

1 answer

✓ Accepted answer
local teleportModule = require(game.ServerScriptService.TeleportModule)

local doorModel = script.Parent
local door = doorModel.Door
local destination = doorModel.Destination
local givescript = doorModel.Money

deBounce = false
waitDelay = 1

door.Touched:Connect(function(hit)
    if deBounce == false then
        deBounce = true 
        -- Get Character
        local character = hit.Parent
        -- Check if Character and Humanoid Health > 0
        if character:FindFirstChild("Humanoid") and character:FindFirstChild("Humanoid").Health > 0 then
            local player = game.Players:GetPlayerFromCharacter(character)
            teleportModule.teleportPlayer(player, destination) -- Trigger Module
            player.leaderstats.Money.Value = player.leaderstats.Money.Value + 100 --Don't use local player, since you only use local player for local scripts(I assume this is a normal script)
        end
        wait(waitDelay)
        deBounce = false
    end
end)

givescript.Disabled = false
wait(3)
givescript.Disabled = true

2 comments

0

i write player.leaderstats.Money.Value = player.leaderstats.Money.Value + 200 but it give 2100 money

0

oh sorry

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