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

Staff Tool Leaderstats Problem? Please Help..

Asked by 4 years ago
Edited 4 years ago

Disclaimer : This Is A Repost Cause On The Other One NO One Answered

Hello, I'm A New Beginner In Scripting And I've Been Making A Simulator game And I've Been Wondering If Anyone Could Make me a Script Which Give 500000 Of The Technology To Specific Players And I Cant Do It So If Anyone Can Do It I Will Be Really Happy. Thanks! btw Heres The Script..

01local db = false
02local tool = script.Parent
03repeat wait() until tool.Parent.Parent:IsA("Player")
04local plr = tool.Parent.Parent
05local character = plr.Character
06 
07tool.Activated:Connect(function()
08    if not db then
09          db = true
10           plr.leaderstats.Technology.Value = plr.leaderstats.Technology.Value + 1
11           wait(1)
12           db = false
13       end
14    end)

1 answer

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

Since you've already got your activated event, you can just put the Character variable inside the Activated event using script.Parent.Parent to get the character, the reason for this is because the Tool is going to be inside the player's Character while they are using the Tool right? So then you can use the Players:GetPlayerFromCharacter to then get the player from the player's Character.

01local db = false
02local tool = script.Parent
03 
04tool.Activated:Connect(function()
05    if not db then
06        db = true
07        local Character = script.Parent.Parent
08        local Player = game.Players:GetPlayerFromCharacter(Character)
09        Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
10        wait(1)
11        db = false
12    end
13end)

To make it so it gives 500000 Technology to a specific player, you can make an if statement to check if the Player.Name or Player.UserId is equal to your name/UserId, depending on what you want, I'd probably recommend using UserId. If you want multiple players to also have access to this, then you can also use a table and insert the players' UserId's into the table then use table.find() to check if their UserId is in the table.

First Example:

01local db = false
02local tool = script.Parent
03 
04tool.Activated:Connect(function()
05    if not db then
06        db = true
07        local Character = script.Parent.Parent
08        local Player = game.Players:GetPlayerFromCharacter(Character)
09        if Player.UserId == 283818237 then -- Put your UserId here
10            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 500000
11        else
12            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
13        end
14        wait(1)
15        db = false
16    end
17end)

Second Example(Table):

01local List = {283818237} -- Put UserId's here
02 
03local db = false
04local tool = script.Parent
05 
06tool.Activated:Connect(function()
07    if not db then
08        db = true
09        local Character = script.Parent.Parent
10        local Player = game.Players:GetPlayerFromCharacter(Character)
11        if table.find(List, Player.UserId) then
12            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 500000
13        else
14            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
15        end
16        wait(1)
17        db = false
18    end
19end)

Sorry if this was a bit much, lol

0
How Do I Do It With Multiple Id's??? Derrick_Dage -128 — 4y
0
Just insert the player's userid into the table, separate them using commas. You could also use a module script for the table so you can access the table from other scripts if you want to insert a player's userid if they have lets say a certain item, or a gamepass. xInfinityBear 1777 — 4y
Ad

Answer this question