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:

01local IsInMatch = game.Players.LocalPlayer.IsInMatch
02 
03function OnTouch(part)
04    IsInMatch.Value = false
05end
06 
07-- simplealgorithm added more to the script below but it doesn't seem to work
08 
09local Spawn = script:FindFirstAncestor("Spawn")
10Spawn.Touched:Connect(function(hit)
11   if (hit ~= nil) then
12      OnTouch(Spawn)
13   end
14end)
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):

01function OnTouch(hit)
02    if hit then
03        local player = nil
04 
05        -- Checking to see if the part that hit it is a character
06        if hit.Parent:FindFirstChild("Humanoid") then
07            player = game.Players:GetPlayerFromCharacter(hit.Parent)
08        -- Special case where a hat hits the spawn rather than a limb
09        elseif hit.Parent.Parent:FindFirstChild("Humanoid") then
10            player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
11        end
12 
13        -- If a player was found through all the checking we did prior to this
14        if player then
15            player.IsInMatch.Value = false
View all 21 lines...
Ad

Answer this question