DumBell Not Working

Hello, im trying to make a DumBell that gives you strength when you click.
for some reason. the leaderstats on the top right wont show.
and you wont get strength.

What I’m trying to make out, is the “leaderstats” script parented to the Tool?

If so, you might want to separate the leaderstats part away(maybe it own script) since multiple player holding a tool while someone joins might add multiple leaderstats to the player(not tested lol). Also why there a click detector for the tool. There a event when clicking while holding a tool.

script.Parent.Activated:connect(function()
--more stuff
end
1 Like

Guess it really is a “DUMB” bell hahahaha!
.
.
.
…
ok i’ll leave now

ok here a basic local tool script - put in in a “LocalScript” parented to the tool

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")

ServerControl = Tool:WaitForChild("ServerControl")

function InvokeServer(Mode)
	pcall(function()
		ServerControl:InvokeServer(Mode)
	end)
end

function Equipped(Mouse)
	local Character = Tool.Parent
	local Player = Players:GetPlayerFromCharacter(Character)
	local Humanoid = Character:FindFirstChild("Humanoid")
	if not Player or not Humanoid or Humanoid.Health == 0 then
		return
	end
	Mouse.Button1Down:connect(function()
		InvokeServer("DumbBell")
	end)
end

local function Unequipped()
	
end

Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)

Then paste this in a “Script” also parented to the tool

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
ServerControl.Name = "ServerControl"
ServerControl.Parent = Tool

ServerControl.OnServerInvoke = (function(player, Mode)
   if Mode == "DumbBell" then
---Put Code here to increment leaderstats by 1 here
   end
end)

If you want me to explain whats going on just ask… But basically the server script is creating a remote function that passes information between the local computer and the roblox server. When the tool is equiped and the player clicks this will be detected by the locl script and then send a message to the server by calling on the remote function using the “Invoke Server” command. The server will then update the leaderstats.

how do i put the code in the normal script at.

umm so you’ll need a script placed in ServerScript Service… That makes the leaderstats folder and strength subfolder… so kinda what you wrote in the first screenshot…
then in the other script you’ll need to lookup that location and add one to the strength value.
you can find most of the answers here:

so i put the normal script you sent me in the ServerScriptService?

The leaderstats script should be in ServerScriptService

it does not work.

my local script:

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Players = game:GetService("Players")

ServerControl = Tool:WaitForChild("ServerControl")

function InvokeServer(Mode)
	pcall(function()
		ServerControl:InvokeServer(Mode)
	end)
end

function Equipped(Mouse)
	local Character = Tool.Parent
	local Player = Players:GetPlayerFromCharacter(Character)
	local Humanoid = Character:FindFirstChild("Humanoid")
	if not Player or not Humanoid or Humanoid.Health == 0 then
		return
	end
	Mouse.Button1Down:connect(function()
		InvokeServer("DumbBell")
	end)
end

local function Unequipped()

end

Tool.Equipped:connect(Equipped)
Tool.Unequipped:connect(Unequipped)

my normal script.

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")
detector = Tool:WaitForChild("ClickDetector")

ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
ServerControl.Name = "ServerControl"
ServerControl.Parent = Tool

ServerControl.OnServerInvoke = (function(player, Mode)
	if Mode == "DumbBell" then

		end
end)

my serverscriptservice code:

local player = game.Players
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local stage = Instance.new("IntValue")
stage.Name = "Strength"
stage.Parent = leaderstats

I suggest using attributes for this.

-- Script in ServerScriptService
local PLYRS : Players = game:GetService("Players")

PLYRS.PlayerAdded:Connect(function(plyr : Player)

    -- Sets the player's default strength
    plyr:SetAttribute("Strength", 0)
end)

local RS : ReplicatedStorage = game:GetService("ReplicatedStorage")
local event : RemoteEvent = RS:WaitForChild("RemoteEvent")

event.OnServerEvent:Connect(function(plyr : Player)

    -- Checks whether the player exists
    if not plyr then return end

    -- Gets the current strength
    local current : number = plyr:GetAttribute("Strength") or 0

    -- Updates the player's strength value
    plyr:SetAttribute("Strength", current += 1)
end)
-- LocalScript parented to the tool

local RS : ReplicatedStorage = game:GetService("ReplicatedStorage")
local event : RemoteEvent = RS:WaitForChild("RemoteEvent")

script.Parent.Activated:Connect(function()
    event:FireServer()
end)

Hope this helps.

So server script service code should read

local Players = game:GetService("Players")

local function leaderboardSetup(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	local strength= Instance.new("IntValue")
	strength.Name = "Strength"
	strength.Value = 0
	strength.Parent = leaderstats
end
-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event

Players.PlayerAdded:Connect(leaderboardSetup)

and normal script should read

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")
detector = Tool:WaitForChild("ClickDetector")

ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
ServerControl.Name = "ServerControl"
ServerControl.Parent = Tool

ServerControl.OnServerInvoke = (function(player, Mode)
	if Mode == "DumbBell" then
print("Clicked")
--then lookup and increments player.leaderstats here!!!!
player.leaderstats.Strength.Value = player.leaderstats.Strength.Value +1
		end
end)