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

How do I access userdata within a Tool?

I made a weapon that holds a basedamage value. I also made a skill-system that allows you to spend Points on Stats like Damage, Speed and Health. How can I access the Stats inside the Local Player with a "normal" script inside my weapon? The stats object inside of the player is in ReplicatedStorage and gets assigned to the player once they enter.

local BaseDamage = script.Parent.BaseDamage.Value
local AddedDamage = --[[ This is the problem. How do I access the stats of the Player? I tried it with game.Players.PlayerAdded, but I only get the Value "nil" for the Damage value inside of stats, but it should be 300.
]]

As always, thanks in advance!

2 comments

0

Tool.Parent will be player's character after Activated is fired. then use game.Players:GetPlayerFromCharacter(Tool.Parent) to get player

0

Thanks! Please write this as an answer so I can accept it!

1 answer

✓ Accepted answer
Tool.Activated:Connect(function()
	local char = Tool.Parent -- Here is the character
	local plr = game.Players:GetPlayerFromCharacter(char) -- Here is the player
end)

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