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

Stats detector to fire an event is not working properly?

I'm doing a script in ServerScriptService that detects if your number of deaths is 0 so it fires the event while if the number is higher than 0 then it doesn't fire the event. I don't even get an error from the workspace and it doesn't even work when I touch the brick. It's a touched event by the way sorry for not informing you about that. Anyways here's the script.

Thanks.

local ts = game:GetService("TweenService")
local part = script.Parent

part.Touched:Connect(function(char)
	local leaderstats = char:FindFirstChild("leaderstats")
	if leaderstats then
		if leaderstats.Deaths.Value == 0 then
			local Info = TweenInfo.new(
				0.76,
				Enum.EasingStyle.Sine,
				Enum.EasingDirection.Out,
				0,
				false,
				0
			)

			local props = {
				Size = Vector3.new(40, 0.5, 33)
			}

			local overall = ts:Create(part,Info,props)

			overall:Play()
		elseif leaderstats.Deaths.Value > 0 then
			return
		end
	end
	
end)


2 comments

0

first of all, part.Touched returns a part, second, parts probably don't have leaderstats

0

ok thanks but how can i fix because when i use a player added event it also doesnt work because i tried it.

1 answer

--###----------[[SERVICES]]----------###--
local TweenService = game:GetService("Players")


local Players = game:GetService("Players")



--###----------[[VARIABLES]]----------###--
local Part = script.Parent



--###----------[[FUNCTIONS]]----------###--
local function OnTouched(AssumedCharacterBodyPart)
	local Humanoid = AssumedCharacterBodyPart:FindFirstChildWhichIsA("Humanoid")
	if (Humanoid) then
		---------------
		local Player = Players:GetPlayerFromCharacter(AssumedCharacterBodyPart.Parent)
		if (Player) then
			---------------
			local DeathStat = Player.leaderstats.Deaths
			if (DeathStat.Value == 0) then
				---------------
				local TweenInfo = TweenInfo.new(
					.75,
					---------------
					Enum.EasingStyle.Sine,
					Enum.EasingDirection.Out
				)
				---------------
				local Properties = { Size = Vector3.new(40, .5, 33); }
				---------------
				TweenService:Create(Part, TweenInfo, Properties):Play()
			end
		end
	end
end



--###----------[[SETUP]]----------###--
Part.Touched:Connect(OnTouched)

3 comments

0

Thanks for trying to help but I used your script and it didn't work, it even didn't print anything in the output when I touched the part.

0

It's not meant to?

0

The code is correct, there is a fault in your work. Ensure this is a Server-script, and is a child of the Part, not ServerScriptService.

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