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.
01 | script.Parent.Touched:Connect( function (hit) |
02 |
03 | local hum = hit.Parent:findFirstChild( "Humanoid" ) |
04 | if hum ~ = nil then |
05 | hit.Parent.HumanoidRootPart.CFrame = CFrame.new( 17 , 10 ,- 61 ) |
06 |
07 | for i,player in ipairs (game.Players:GetPlayers()) do |
08 | if player.Character then |
09 | local stat = player:FindFirstChild( "leaderstats" ) |
10 | if stat then |
11 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 5 |
12 |
13 |
14 | end |
15 | end |
16 | end |
17 | end |
18 | end ) |
Can you please help me. Thank you
put this script in a part
01 | ----------------------------------------------------------------- |
02 | --Made 100% by Eternalove_fan32 please Credits |
03 | ----------------------------------------------------------------- |
04 |
05 | game.Players.PlayerAdded:Connect( function (player) |
06 | local debounce = false |
07 | local leaderstats = Instance.new( "Folder" ,player) |
08 | leaderstats.Name = "leaderstats" |
09 | local Money = Instance.new( "IntValue" ,leaderstats) |
10 | Money.Name = "Money" |
11 | Money.Value = 0 |
12 |
13 | script.Parent.Touched:Connect( function (hit) |
14 |
15 | local hum = hit.Parent:findFirstChild( "Humanoid" ) |
If you want it to be random, (reward) then you can add a table, and use math.random
01 | local PossibleRewards = { 5 , 10 , 15 , 20 } |
02 | script.Parent.Touched:Connect( function (hit) |
03 |
04 | local hum = hit.Parent:findFirstChild( "Humanoid" ) |
05 | if hum ~ = nil then |
06 | hit.Parent.HumanoidRootPart.CFrame = CFrame.new( 17 , 10 ,- 61 ) |
07 |
08 | for i,player in ipairs (game.Players:GetPlayers()) do |
09 | if player.Character then |
10 | local stat = player:FindFirstChild( "leaderstats" ) |
11 | if stat then |
12 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + math.random( 1 ,#PossibleRewards) |
13 |
14 |
15 | end |
16 | end |
17 | end |
18 | end |
19 | end ) |
You can teleport Model
with :MoveTo( vector3 )
Ex:
1 | hit.Parent:MoveTo(Vector 3. new( 17 , 10 ,- 61 )) |
Script:
01 | script.Parent.Touched:Connect( function (hit) |
02 |
03 | local hum = hit.Parent:FindFirstChild( "Humanoid" ) |
04 | if hum ~ = nil then |
05 | hit.Parent:MoveTo(Vector 3. new( 17 , 10 ,- 61 )) |
06 |
07 | for i,player in ipairs (game.Players:GetPlayers()) do |
08 | if player.Character then |
09 | local stat = player:FindFirstChild( "leaderstats" ) |
10 | if stat then |
11 | player.leaderstats.Money.Value = player.leaderstats.Money.Value + 5 |
12 |
13 |
14 | end |
15 | end |
16 | end |
17 | end |
18 | end ) |