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..

local db = false
local tool = script.Parent
repeat wait() until tool.Parent.Parent:IsA("Player")
local plr = tool.Parent.Parent
local character = plr.Character

tool.Activated:Connect(function()
    if not db then
          db = true
           plr.leaderstats.Technology.Value = plr.leaderstats.Technology.Value + 1
           wait(1)
           db = false
       end
    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.

local db = false
local tool = script.Parent

tool.Activated:Connect(function()
    if not db then
        db = true
        local Character = script.Parent.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
        wait(1)
        db = false
    end
end)

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:

local db = false
local tool = script.Parent

tool.Activated:Connect(function()
    if not db then
        db = true
        local Character = script.Parent.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        if Player.UserId == 283818237 then -- Put your UserId here
            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 500000
        else
            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
        end
        wait(1)
        db = false
    end
end)

Second Example(Table):

local List = {283818237} -- Put UserId's here

local db = false
local tool = script.Parent

tool.Activated:Connect(function()
    if not db then
        db = true
        local Character = script.Parent.Parent
        local Player = game.Players:GetPlayerFromCharacter(Character)
        if table.find(List, Player.UserId) then
            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 500000
        else
            Player.leaderstats.Technology.Value = Player.leaderstats.Technology.Value + 1
        end
        wait(1)
        db = false
    end
end)

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