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

Why doesn't the Changed function work properly?

local lplayer = game.Players.LocalPlayer
repeat wait() until lplayer.Character.Head 
local Head = lplayer.Character.Head
local RS = game:GetService("RunService") 
local HumT = lplayer.Character.Torso
local Loc = lplayer.Character

RS.Stepped:connect(function() 
    Head.CanCollide = false
	HumT.CanCollide = false
end)

Loc.Changed:connect(function(Property)
    if Property == "CanCollide" then
        Head.CanCollide = false
		HumT.CanCollide = false
    end
end)


It changes Head / Torso from Player2 but not to Player1 when you do the Server Simulation with 2 players. And this is supposed to overwrite to each local player, can't understand why it's doing that...

1 comment

0

Changed detects a change in a value, Character is not a value it is a model.

2 answers

✓ Accepted answer

Not sure if it'll work in online mode, but it works in studio so far

I made it wait until the head is found, usually WaitForChild is a good way to get stuff inside the character.

local lplayer = game.Players.LocalPlayer
repeat wait() until lplayer.Character:WaitForChild('Head')
local Head = lplayer.Character.Head
local RS = game:GetService("RunService") 
local HumT = lplayer.Character.Torso
local Loc = lplayer.Character

RS.Stepped:connect(function() 
    Head.CanCollide = false
    HumT.CanCollide = false
end)

Loc.Changed:connect(function(Property)
    if Property == "CanCollide" then
        Head.CanCollide = false
        HumT.CanCollide = false
    end
end)


1 comment

0

The issue here is that, with 1 player, when you test it out, it goes CanCollide false, but when you start a Server with 2+ players, only 1 of them is affected by CanCollide = false, so I don't know how to fix it up, tried to make a table, but as you can see it didn't work at all.

It should've work now but it doesn't, I've did a table with the parts, and it still doesn't cancollide to every player in the Simulated Server.

local lplayer = game.Players.LocalPlayer
repeat wait() until lplayer.Character.Head 
local Head = lplayer.Character.Head
local RS = game:GetService("RunService") 
local HumT = lplayer.Character.Torso
local Loc = {lplayer.Character.Torso, lplayer.Character.Head, lplayer.Character.HumanoidRootPart}

RS.Stepped:connect(function() 
    Head.CanCollide = false
	HumT.CanCollide = false
end)

lplayer.Changed:connect(function(Property)
    if Property == "CanCollide" then
        for i,v in pairs(Loc) do
		v.CanCollide = false
end
    end
end)

I have no output errors.

1 comment

0

The function closing, dont you need like ())

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