Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesn't the Changed function work properly?

Asked by 8 years ago
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...

0
Changed detects a change in a value, Character is not a value it is a model. JJ_B 250 — 8y

2 answers

Log in to vote
0
Answered by
yoshi8080 445 Moderation Voter
8 years ago

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)


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. iDarkGames 483 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

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.

0
The function closing, dont you need like ()) iNicklas 215 — 8y

Answer this question