How do I get the player's leaderstats from this script?

Line 22 is erroring with ‘WeaponValue is not a valid member of Folder “he4rtsformoonlight.leaderstats”’

local teleportPart = script.Parent
local locations = {}
local debounce = false

for i = 1, 9 do
	local locationPart = game.Workspace.Locations:FindFirstChild("Location" .. i)
	if locationPart then
		table.insert(locations, locationPart)
	end
end

if teleportPart then
	teleportPart.Touched:Connect(function(hit)
		if debounce then return end
		debounce = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local locationPart = locations[math.random(1, #locations)]
			player.Character.HumanoidRootPart.CFrame = locationPart.CFrame
			game.Workspace.Sounds["bass.wav"]:Play()
			
			local WeaponValue = hit.Parent.leaderstats:WaitForChild("Weapon")
			
			local SwordsmanTool = game.ServerStorage.Weapons.Swordsman
			
			if WeaponValue.Value == "Swordsman" then
				local newSwordsmanTool = SwordsmanTool:Clone()
				newSwordsmanTool.Parent = player.Backpack
			end
		end
		wait(1)
		debounce = false
	end)
end
1 Like

Is your leaderstats script set up correctly??

Maybe send that script over too

2 Likes

" local WeaponValue = hit.Parent.leaderstats:WaitForChild(“Weapon”) "
try replacing WaitForChild() with FindFirstChild()

1 Like

is this a Name or IntValue?

I fixed something in leaderstats, Now it just says leaderstats is not a valid member of Model "Workspace.he4rtsformoonlight" - Server - Script:22

1 Like

That’s because you’re trying to find the leaderstats folder inside of the players character, instead try finding the leaderstats folder by using;

game.Players.PLAYER_NAME.leaderstats

You would get the player name from finding the person who touched the parts characters name.

2 Likes

Should work

local teleportPart = script.Parent
local locations = {}
local debounce = false

for i = 1, 9 do
	local locationPart = game.Workspace.Locations:FindFirstChild("Location" .. i)
	if locationPart then
		table.insert(locations, locationPart)
	end
end

if teleportPart then
	teleportPart.Touched:Connect(function(hit)
		if debounce then return end
		debounce = true
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player then
			local locationPart = locations[math.random(1, #locations)]
			player.Character.HumanoidRootPart.CFrame = locationPart.CFrame
			game.Workspace.Sounds["bass.wav"]:Play()
			
			local WeaponValue = player.leaderstats:WaitForChild("Weapon")
			
			local SwordsmanTool = game.ServerStorage.Weapons.Swordsman
			
			if WeaponValue.Value == "Swordsman" then
				local newSwordsmanTool = SwordsmanTool:Clone()
				newSwordsmanTool.Parent = player.Backpack
			end
		end
		wait(1)
		debounce = false
	end)
end
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.