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

How to teleport a playen and give him money when touched a brick?

Asked by 5 years ago

I made a parcour and i want that when a player touched the end brick. he teleports back and add 5 money. now i have this, But when i now stand on the end brick i get 5, 10, 15 or 20 money.

this is the scripts.

script.Parent.Touched:Connect(function(hit)

        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(17,10,-61)

            for i,player in ipairs(game.Players:GetPlayers()) do
                if player.Character then
                    local stat = player:FindFirstChild("leaderstats")
                    if stat then
                        player.leaderstats.Money.Value = player.leaderstats.Money.Value +5


                end
            end
        end
    end
end)

Can you please help me. Thank you

0
Does it print any errors? fortesss7 40 — 5y
0
Where it says CFrame.new(17,10,-61), you need to change it to CFrame.new(Vector3.new(17, 10, -61)) Unhumanly 152 — 5y
0
I had a question similar to this! Sadly, none of the answers I got worked. check out my question, the link is: https://scriptinghelpers.org/questions/84971/how-to-loop-through-each-player-and-add-currency-if-they-destroy-a-building NickIsANuke 217 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

put this script in a part

-----------------------------------------------------------------
--Made 100% by Eternalove_fan32 please Credits
-----------------------------------------------------------------

game.Players.PlayerAdded:Connect(function(player)
local debounce = false
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local Money = Instance.new("IntValue",leaderstats)
Money.Name = "Money"
Money.Value = 0

script.Parent.Touched:Connect(function(hit)

        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil and debounce == false then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(173, 3.5, 236) --You can use the position with what you need
            for i,player in ipairs(game.Players:GetPlayers()) do
                if player.Character then
                    local stat = player:FindFirstChild("leaderstats")
                    if stat then
                        player.leaderstats.Money.Value = player.leaderstats.Money.Value +5

                    end

            debounce = true
            wait(2)
            debounce = false


                end
            end
        end
    end)
end)
0
I hope this can help you further Eternalove_fan32 188 — 5y
0
It worked thank you. srry for late reaction i was on vacation. SwimBotTi 2 — 5y
0
its okey Eternalove_fan32 188 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

If you want it to be random, (reward) then you can add a table, and use math.random

local PossibleRewards = {5,10,15,20}
    script.Parent.Touched:Connect(function(hit)

        local hum = hit.Parent:findFirstChild("Humanoid")
        if hum ~= nil then
            hit.Parent.HumanoidRootPart.CFrame = CFrame.new(17,10,-61)

            for i,player in ipairs(game.Players:GetPlayers()) do
                if player.Character then
                    local stat = player:FindFirstChild("leaderstats")
                    if stat then
                        player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random(1,#PossibleRewards)


                end
            end
        end
    end
end)
0
I didn't want it to be random. but thanks. srry for late reaction i was on vacation. SwimBotTi 2 — 5y
Log in to vote
0
Answered by
OnaKat 444 Moderation Voter
5 years ago
Edited 5 years ago

You can teleport Model with :MoveTo( vector3 )

Ex:

hit.Parent:MoveTo(Vector3.new(17,10,-61))

Script:

script.Parent.Touched:Connect(function(hit)

        local hum = hit.Parent:FindFirstChild("Humanoid")
        if hum ~= nil then
            hit.Parent:MoveTo(Vector3.new(17,10,-61))

            for i,player in ipairs(game.Players:GetPlayers()) do
                if player.Character then
                    local stat = player:FindFirstChild("leaderstats")
                    if stat then
                        player.leaderstats.Money.Value = player.leaderstats.Money.Value +5


                end
            end
        end
    end
end)

Answer this question