script.Parent.Player:GetPropertyChangedSignal("Value"):Connect(function()
if script.Parent.Player.Value:IsA("Player") then
game:GetService("RunService").Stepped:Connect(function()
script.Parent.CFrame = script.Parent.Player.Value.Character.HumanoidRootPart.CFrame
end)
end
end)
script.Parent.Touched:Connect(function(part)
print(part)
if not(part.Parent == script.Parent.Player.Value.Character) then
if part.Parent:FindFirstChildOfClass("Humanoid") then
part.Parent:FindFirstChildOfClass("Humanoid").Health = 0
end
end
end)
local Part = Instance.new("Part")
Part.Size = Vector3.new(3, 6.5, 3)
Part.Anchored = true
Part.Transparency = 0.5
Part.CanCollide = false
Part.Parent = workspace
game:GetService("RunService").Stepped:Connect(function()
Part.CFrame = script.Parent.HumanoidRootPart.CFrame
local OverlapParameters = OverlapParams.new()
OverlapParameters.MaxParts = math.huge
OverlapParameters.FilterDescendantsInstances = script.Parent:GetDescendants()
local PartsInPart = workspace:GetPartsInPart(Part, OverlapParameters)
for i, part in pairs(PartsInPart) do
if part.Parent:FindFirstChildOfClass("Humanoid") then
part.Parent:FindFirstChildOfClass("Humanoid").Health = 0
end
end
end)
RunService.RenderStepped does not work on serverscripts
I know this is solved but for future reference use the ‘Changed’ event/signal when using value objects.
local Parent = script.Parent
local Player = Parent.Player
local function OnChanged(Value)
if Value:IsA("Player") then
--Do code.
end
end
Player.Changed:Connect(OnChanged)
No they don’t, the ‘Changed’ event/signal behaves differently for value object instances. https://developer.roblox.com/en-us/api-reference/event/IntValue/Changed
It only fires when the ‘Value’ property changes and it passes the new value of its ‘Value’ property to any connected callback functions.