Teleporter that gives a tool when teleported according to a StringValue not working

My idea was a teleporter that has a StringValue, and if it is something like “Default” as the value, it will then give the Default tool. However, it doesn’t seem to work for some reason…

local NormTP = game.Workspace.lobby.NAT
local leaderboard = game.Players
local s = math.random(1, 2)

-- balls
local Ball = game.ServerStorage.Default --> Default Ball <--
local LightningBall = game.ServerStorage.Lightning

NormTP.Touched:Connect(function(player)
	local leaderstat = player:WaitForChild("leaderstats")
	if leaderstat.Ball.Value == "Default" then
		local CloneBall = Ball:Clone()
		CloneBall.Parent = player.Backpack
		CloneBall.Enabler.Enabled = true
	else
		if leaderstat.Ball.Value == "Lightning" then
			local LightBall = LightningBall:Clone()
			LightBall.Parent = player.BackPack
			LightBall.Enabler.Enabled = true
		end
	end
end)

NormTP.Touched:Connect(function(player)
	if s == 1 then
		player.CFrame = CFrame.new(0.7, 9.8, -8.3)
	else
		if s == 2 then
			player.CFrame = CFrame.new(0.7, 9.8, 41.2)
		end
	end
end)
1 Like

Your detection script makes sense, but I think you are trying to search a part on the character for leaderstats.

local Players = game:GetService("Players")

NormTP.Touched:Connect(function(touched)
	-- The argument that is passed when detecting
	-- a BasePart touch is the part that touched it.
	local character = touched.Parent
	local player = Players:GetPlayerFromCharacter(character)
	if player then
		-- Put code here
	end
end)

You can view more on the .Touched event here.

Hope this helps!

1 Like