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

How do I make a stat increasing tool?

Asked by 4 years ago
Edited 4 years ago

How do I make a tool that increases your stat like in one of those simulators? The code I'm trying to use won't work. Here's the code.

holdername = nil;

script.Parent.Equipped:connect(function()
    holdername = script.Parent.Parent.Name;
end)

script.Parent.Unequipped:connect(function()
    holdername = nil;
end)

script.Parent.Activated:connect(function()
    -- game.Players.holdername.leaderstats["Cheezburgers"].Value = game.Players.holdername.leaderstats["Cheezburgers"].Value + 1;
    -- 14:33:38.767 - holdername is not a valid member of Players
    -- Judging by this, I cannot detect a player by their name using a string variable/value.
end)

script.Parent.Deactivated:connect(function()
    print(holdername.." ate a cheezburger!")
end)

Basically, it says that "holdername is not a valid member of Players" because there is no player named holdername, resulting in a error while it was expected to actually find a player with that name stored in the string variable/value to look into them to increase their stats. However, the expected part wasen't supported/able to work because it doesn't have that functionality, meaning I'll have to find a other way. Can someone help? Thanks.

If the stat handler script code is required, it is

game.Players.PlayerAdded:connect(function(player)
    leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats";
    cheezburgers = Instance.new("IntValue", leaderstats)
    cheezburgers.Name = "Cheezburgers";
end)

The scripts mentioned in here are BY ME ONLY. This is also a solo project.

0
I upvoted this because many people need to learn these things. aandmprogameing 52 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

removing holdername = nil might work and make it holdername. Otherwise, you can try this:

Step 1: Make a RemoteEvent called 'Give' and put it in ReplicatedStorage. Step 2: Make a script and name it 'Function' and place it in ServerScriptService. Here's the code for that:

local remote = game.ReplicatedStorage.Give

remote.OnServerEvent:Connect(function(Player)
    local plr = Player
    plr.leaderstats.Cash.Value = plr.leaderstats.Cash.Value + 1
end)

Step 3: Clearly the leaderboard in ServerScriptService:

game.Players.PlayerAdded:connect(function(p)
    local stats = Instance.new("IntValue")
    stats.Name = "leaderstats"
    stats.Parent = p

    local money = Instance.new("IntValue")
    money.Name = "Cash"
    money.Value = 0
    money.Parent = stats
end)

Step 4: Now create a screengui in StarterGui and name it 'popUp' Step 5: Then insert a 'TextLabel' (You can use a ImageLabel but u will have to change the code in the tool later on) into the popUp and set these properties:

  • Visible: False
  • TextScaled: True
  • BackgroundTransparency = 1
  • and any other settings should be okay, expect TextTransparency.

Step 6: Now name the text label 'ImageLabel' If you decided to use a ImageLabel instead, this step isn't needed.

Step 7: Create a tool with a handle.

Create a tool and name it 'Cash Giver' or whatever you please. then place a part inside it and name it handle, customize that handle, then place the tool in StarterPack.

Step 8: Add scripts and tool settings

Make sure the tool has these settings:

  • RequiresHandle: True
  • CanBeDropped: False
  • Enabled: True
  • ManualActivation: False
  • Archivable: True

Now let's make the scripts:

Script 1: add a local script and name it 'Detector' then insert this code into it:

script.Parent.Unequipped:Connect(function()
    script.Parent.LocalScript.Disabled = true
end)

script.Parent.Equipped:Connect(function()
    script.Parent.LocalScript.Disabled = false
end)

Script 2: add a local script and do not name it, then insert this code into it:

local remote = game.ReplicatedStorage.Give

script.Parent.Equipped:Connect(function()
    if script.Parent.Equipped then
                game.Players.LocalPlayer:GetMouse().Button1Down:Connect(function()
                local plr = game.Players.LocalPlayer
                plr.PlayerGui.popUp.ImageLabel.Position = UDim2.new(0, plr:GetMouse().X, 0, plr:GetMouse().Y)
                plr.PlayerGui.popUp.ImageLabel.Visible = true
                script.Disabled = true
                remote:FireServer()
                for i = 1, 10 do
                    wait()
                    plr.PlayerGui.popUp.ImageLabel.TextTransparency = plr.PlayerGui.popUp.ImageLabel.TextTransparency - 0.1
                end
                wait(0.5)
                for i = 1, 10 do
                    wait()
                 plr.PlayerGui.popUp.ImageLabel.TextTransparency = plr.PlayerGui.popUp.ImageLabel.TextTransparency + 0.1
                end
                plr.PlayerGui.popUp.ImageLabel.Visible = false
                script.Disabled = false
            end)
        end
    end)

If you plan on using a ImageLabel instead, it's very simple to change:

-- Old:
plr.PlayerGui.popUp.ImageLabel.TextTransparency = plr.PlayerGui.popUp.ImageLabel.TextTransparency - 0.1
-- New:
plr.PlayerGui.popUp.ImageLabel.ImageTransparency =  plr.PlayerGui.popUp.ImageLabel.ImageTransparency - 0.1  
-- and clearly change where the + is instead of the -, change the wording to ImageTransparency.

Please accept if this worked! Also please give credit.

Ad
Log in to vote
0
Answered by 4 years ago

Explanation: 1.You need to capitalize the C's in Connect because that is the new form of connect. 2.Your holdername is being named Backpack because you need one more parent for the player. 3.You need to use :FindFirstChild to get any player in players for variables.

holdername = nil;

script.Parent.Equipped:Connect(function()
    holdername = script.Parent.Parent.Parent.Name;
end)

script.Parent.Unequipped:Connect(function()
    holdername = nil;
end)

script.Parent.Activated:Connect(function()
    -- game.Players:FindFirstChild(holdername).leaderstats["Cheezburgers"].Value = game.Players:FindFirstChild(holdername).leaderstats["Cheezburgers"].Value + 1;
    -- 14:33:38.767 - holdername is not a valid member of Players
    -- Judging by this, I cannot detect a player by their name using a string variable/value.
end)

script.Parent.Deactivated:Connect(function()
    print(holdername.." ate a cheezburger!")
end)
0
It didn't work, because of that "Workspace ate a cheezburger!" thing I got. But there was no references to Workspace in your code, ROBLOX is glitchy. TrustedInstaIler 17 — 4y
0
I also get a Players.Logan_Developer.Backpack.Cheezburger.StatGiver:12: attempt to index a nil value TrustedInstaIler 17 — 4y

Answer this question