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

Freeze brick not working; how can I alter it?

EDIT: I just realized I forgot to do Touched instead of PlayerAdded.. dang.

Hey.

Y'all remember TwoShue's Freeze Tag came from like 2010-2011? Fun stuff. I'm trying to recreate it somewhat, but instead of another humanoid touching another, I'm going simpler and trying to get players frozen by touching a brick. Problem is, every time I run the code, I get:


"Workspace.FreezingPart.Script:10: attempt to index nil with 'FindFirstChild'"


Here's my code for reference:


local PlayersService = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(hit)

	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

	local freezePart = Instance.new("Part", workspace)

	freezePart.Anchored = true

	freezePart.Material = "Neon"

	freezePart.CanCollide = false

	freezePart.Size = Vector3.new(5, 5.5, 4)

	freezePart.CFrame = CFrame.new(plr:FindFirstChild('HumanoidRootPart').Position)

	freezePart.Parent = plr

end)

How can I remediate the error? I've tried messing about with a local character, a local player's position, etc., but I'm struggling. I know the script isn't finished yet: I haven't altered the player's anchoring, transparency, etc. after he touches the brick, but I really just want the brick to appear at his/her location first, above all else. Any help would be appreciated. Thank you in advance.

2 comments

0

Your trying to get a player from a player. Replace line 3 with "game.Players.PlayerAdded:Connect(function(plr)", delete line 5, and delete line 1. You should have a working script

0

Thank you bro!

1 answer

Wouldn't it be easier to anchor the HumanoidRootPart?

-- Put this inside ServerScriptService
local players = game:GetService("Players")
local freezePart, freezeWeld
players.PlayerAdded:Connect(function(player) -- Wait for players
	player.CharacterAdded(function(character) -- Wait for character
		if not character:FindFirstChild("FreezePart") -- If there isn't already a freezepart
			local freezePart = Instance.new("Part", workspace) -- Create freezepart
			freezePart.Anchored = false
			freezePart.Material = "Neon"
			freezePart.CanCollide = false
			freezePart.Size = Vector3.new(5, 5.5, 4)
			freezePart.CFrame = character.HumanoidRootPart.CFrame
			freezePart.Parent = plr
			freezePart.Transparency = 1
			freezePart.Name = "FreezePart"
			local freezeWeld = Instance.new("WeldConstraint", freezePart) -- Attach to character
			freezeWeld.Part0 = freezePart
			freezeWeld.Part1 = character.HumanoidRootPart.CFrame
			freezeWeld.Name = "FreezeWeld"
		end
	end)
end)
-- Put this inside the brick
local players = game:GetService("Players")
local freezeTime = 2
local freezePart

script.Parent.Touched:Connect(function(otherPart) -- Wait until touched
	if players[otherPart.Parent.Name] then -- If player found
		freezePart = otherPart.Parent.FreezePart -- Activate freeze
		freezePart.Anchored = true
		freezePart.Transparency = 0
		wait(freezeTime) -- Wait 
		freezePart.Anchored = false -- Deactivate freeze
		freezePart.Transparency = 1
	end
end)

2 comments

0

Lol just realised you were going to do the rest AFTER, oopsie

0

Thank you for the response. I just noticed I did PlayerAdded instead of Touched and didn't really grab Players properly. I'll try the script, thanks!

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