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

When a player walks over a spawn it won't change the value of the boolvalue?

Asked by 6 years ago

When a player walks over a spawn it sets a bool value (IsInMatch) to false. When the bool value is set to true the GUI is Invisible, but when the boolvalue is false the GUI is visible. Although, that's not the problem. the problem is that when I walk over my spawn, it won't change the value of the boolvalue, hence letting the GUI not disappear.

simplealgorithm added to the script but it still doesn't work.

here is the local script inside the spawn:

local IsInMatch = game.Players.LocalPlayer.IsInMatch

function OnTouch(part)
    IsInMatch.Value = false
end

-- simplealgorithm added more to the script below but it doesn't seem to work

local Spawn = script:FindFirstAncestor("Spawn")
Spawn.Touched:Connect(function(hit)
   if (hit ~= nil) then
      OnTouch(Spawn)
   end
end)
0
Local Scripts need to be under the player for them to run. Put this under StarterPlayerScripts and correct the "Spawn" variable path. xPolarium 1388 — 6y

1 answer

Log in to vote
2
Answered by
nilVector 812 Moderation Voter
6 years ago
Edited 6 years ago

This is simply because LocalScripts do not work in the server. The spawn, which I am assuming is somewhere in the Workspace, is a part of the server.

You need to be handling all this in a normal, server script. Now, since this is a server script, game.Players.LocalPlayer would not work, because it wouldn't make sense for the server to have a local player.

To find the player who touched the Spawn part, you can simply check to see if the hit parameter passed through the Touched event can tell you information about an existing player.

It can be done so like this (in a server script):

function OnTouch(hit)
    if hit then
        local player = nil

        -- Checking to see if the part that hit it is a character
        if hit.Parent:FindFirstChild("Humanoid") then
            player = game.Players:GetPlayerFromCharacter(hit.Parent)
        -- Special case where a hat hits the spawn rather than a limb
        elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
            player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
        end

        -- If a player was found through all the checking we did prior to this
        if player then
            player.IsInMatch.Value = false
        end
    end
end

local Spawn = script.Parent -- no need for FindFirstAncestor
Spawn.Touched:Connect(OnTouch)
Ad

Answer this question