|
Script
local SafeZB = script.Settings.SafeZone -- SafeZone is a BoolValue
safeZ.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player and player==game.Players.LocalPlayer then -- Making sure player is local
SafeZB.Value = true -- Changing the Value to true
end
end)
if SafeZB.Value == true then -- Dunno
while SafeZB.Value == true do -- Dunno
if player and player==game.Players.LocalPlayer then -- Player is local
PatrolAnim() -- Cfram Anim
PatrolMode=true
end
end
end
I'm trying to make it when SafeZB value is true it will run
PatrolAnim()
PatrolMode=true
|
|
|
|
|
|
A couple of things. "player" would be 'local' to the function you defined, hence 'local'. The would not be able to use the "player" variable in the loop since it is outside of the function. Also, you defined your loop inside of the if statement. What this does will initially check for the value (which is probably false at this point) at the start of the script. Since it is probably false, the while loop will never run. You can try this, though it will probably be a little 'hacky', post results.
local SafeZB = script.Settings.SafeZone -- SafeZone is a BoolValue
safeZ.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player then
SafeZB.Value = true -- Changing the Value to true
while SafeZB.Value and Wait() do
if player.Character then
PatrolAnim()
PatrolMode=true
end
end
end
end) |
|
|
To clarify since my English is terrible apparently:
You set "player" variable's scope to the Touched function. You cannot use this outside of it.
Also, you defined your loop inside of the if statement. The loop will not run at all unless the condition to the if statement is true when it is first checked. |
|
|
Yeah works but it keeps looping.. safeS.Touched:Connect(function(hit) -- Touched function local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player if player then SafeZB.Value = false -- Changing the Value to true while SafeZB.Value and wait() do if player.Character then IdleAnim() PatrolMode = false end end end end) I used that so when player hits a sec part it will run it but it don't work because I dunnno... prob looping the first one ################ ################# yeah |
|
|
Yeah works but it keeps looping..
safeS.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player then
SafeZB.Value = false -- Changing the Value to true
while SafeZB.Value and wait() do
if player.Character then
IdleAnim()
PatrolMode = false
end
end
end
end)
I used that so when player hits a sec part it will run it but it don't work because I dunnno... probably looping
|
|
|
Yes it should keep looping until SafeZB.Value is false. Sorry, I wasn't exactly clear on what you wanted. What is continuously happening, and when do you want it to stop looping? |
|
|
Thanks btw,
Yeah so when player walks into a part Value will go to true and run the anim
When player walks into the sec part it will set the value to false and run the anim
FIRST PART (SafeZone Part) local safeZ=workspace.NOSOT
SEC PART (Out of SafeZone Part) local safeS=workspace.SOT
|
|
|
If anything I can just add you and invite you to a team crate>?
|
|
|
Do you have the code of the second part? And did you want the animation in the first part to continue running until it is false? |
|
|
local safeZ=workspace.NOSOT
local safeS=workspace.SOT
local SafeZB = script.Settings.SafeZone
------(SAFEZONE)-----
safeZ.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player then
SafeZB.Value = true -- Changing the Value to true
while SafeZB.Value and Wait() do
if player.Character then
PatrolAnim()
PatrolMode=true
end
end
end
end)
------(OUT OF SAFEZONE)-----
safeS.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player then
SafeZB.Value = true -- Changing the Value to true
while SafeZB.Value and Wait() do
if player.Character then
IdleAnim()
PatrolMode = false
end
end
end
end)
|
|
|
So when player walks into safezone run Anim 1 then when player walks into part2 runs anim2
|
|
|
------(OUT OF SAFEZONE)-----
safeS.Touched:Connect(function(hit) -- Touched function
local player=game.Players:GetPlayerFromCharacter(hit.Parent) -- Getting Player
if player then
SafeZB.Value = false -- Changing the Value to true
while SafeZB.Value and Wait() do
if player.Character then
IdleAnim()
PatrolMode = false
end
end
end
end)
|
|
|