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

My safe zone script wont work it basicly dont make gui visible and ? dunno why?

Asked by
gjlkv1 11
4 years ago
local Model = script.Parent
local SafeZoneDetector = Model:WaitForChild("SafeZoneDetector")
SafeZoneDetector.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent:FindFirstChild ("SafeZone Protection") == nil then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        game.Players.LocalPlayer.PlayerGui.ScreenGui.safed.Visible = true
        local Forcefield = Instance.new("ForceField")
        Forcefield.Name = "SafeZone Protection"
        Forcefield.Visible = false
        Forcefield.Parent = hit.Parent
    end
end)

SafeZoneDetector.TouchEnded:Connect(function(hit)
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
    local object = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
object:TweenSize(UDim2.new(0, 0, 0, 0), nil, nil, 60)
    wait (60)
    if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent:FindFirstChild ("SafeZone Protection") == nil then
        hit.Parent:FindFirstChild("SafeZoneProtection"):Destroy()
    end
end) 

? made this safe zone script but it wont work and ? am not able to see any erors in output any help please

1 answer

Log in to vote
0
Answered by
compUcomp 417 Moderation Voter
4 years ago
Edited 4 years ago

This script is stored in a model that contains the safe-zone, but it's a LocalScript? Part of your script handles the ForceField, and another part handles the GUI. This isn't possible from one script (the ForceField would be local). What you need to do is separate it into two scripts.

Script inside model:

local Model = script.Parent
local SafeZoneDetector = Model.SafeZoneDetector
SafeZoneDetector.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent:FindFirstChild ("SafeZone Protection") == nil then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        game.Players.LocalPlayer.PlayerGui.ScreenGui.safed.Visible = true
        local Forcefield = Instance.new("ForceField")
        Forcefield.Name = "SafeZone Protection"
        Forcefield.Visible = false
        Forcefield.Parent = hit.Parent
    end
end)

LocalScript anywhere where LocalScripts run:

local Model = Path.To.Model
local SafeZoneDetector = Model:WaitForChild("SafeZoneDetector")

SafeZoneDetector.Touched:Connect(function(hit)
        if hit.Parent:FindFirstChild("Humanoid") and hit.Parent:FindFirstChild("HumanoidRootPart") and hit.Parent:FindFirstChild ("SafeZone Protection") == nil then
        local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
        if player == game.Players.LocalPlayer then
        game.Players.LocalPlayer.PlayerGui.ScreenGui.safed.Visible = true
    end
    end
end)

SafeZoneDetector.TouchEnded:Connect(function(hit)
    game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.Visible = true
    local object = game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame
    object:TweenSize(UDim2.new(0, 0, 0, 0), nil, nil, 60)
end) 

Please excuse any typing mistakes I make, I'm writing this on mobile

0
Glad I could help :D compUcomp 417 — 4y
Ad

Answer this question