Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Detect a specific int Value inside an equipped tool?

Most solutions I have found online is detecting the value inside the player backpack or rather. Detecting the tool itself with a specific name.

How my game works are players have a tool called Shotgun. This tool has an int Value inside it that increases with every new shotgun you get and its main purpose is determining how many Skulls you get every click. All guns have another value for the price.

All calculations so far are done serverside with a bit of debounce.

local replicaredStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")


local cooldown = 1

replicaredStorage.Remotes.Skull.OnServerEvent:Connect(function(player)
	
	if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end
	local debounce = remoteData[player.Name].Debounce
	
	if not debounce.Value then
		debounce.Value = true
		player.leaderstats.Skulls.Value = player.leaderstats.Skulls.Value + 5 * (player.leaderstats.Rebirths.Value + 1)
		
		wait(cooldown)
		
		debounce.Value = false
	end
	
end)

You can see the "+5" that is in there. What I want to have is a + "Value inside of the currently equipped weapon". I could mention that this script is inside of ServerScriptService.

I want the script to check inside the currently equipped tool for the value named "Skull" that holds the number 5 instead.

2 answers

✓ Accepted answer

First you would have to find the tool, considering the value is inside the tool right? local Tool = Player.Character:FindFirstChildOfClass("Tool") or Player.Backpack:FindFirstChild("ToolName")

With this tool defined you can find the value called "Skull"

local SkullValue = Tool:FindFirstChild("Skull")

Then with this value defined you can add it to your calculations

leaderstats.Skulls.Value = leaderstats.Skulls.Value + SkullValue.Value * (leaderstats.Rebirths.Value + 1)

1 comment

0

Thank you. After fibbeling around a bit with your suggestion I got it to work! You've been huge help!

I am guessing this script is directly inside of the character (workspace model)? When a character is holding tool, the tool's new parent is the character. You can access the tool like that.

----
----
-- add this into your script
local parts  = script.Parent:GetChildren()
local tool
for i = 1, #parts do
	local focus = part[i]
	if focus:IsA("Tool") then
	tool = focus
	end
end
--

--  the next lines are 12 - 15 in your script, but modified. I took out "5" and replaced it.

if not debounce.Value then
debounce.Value = true
player.leaderstats.Skulls.Value = player.leaderstats.Skulls.Value + tool.URVALUE.Value* (player.leaderstats.Rebirths.Value + 1)
-- that should work.
--

This will work if this script is located inside the character model. If this isn't what you intended, then respond to this and I will help you.

This discussion is preserved as it was. New answers, comments, and votes are closed.