Search code examples
roblox

Im making a PropHunt game in roblox but the whenever i morph the player character into a new form the UI keeps on being called


I have this project, im creating a prophunt game, however im in a little road block that i can't understand.

Here is how my code works, I have a local script which tells me which team the player is in, since the player does not have a team yet they are always assumed as neutral, then the local script is called whenever the players are added, which a GUI appears, allowing for them to pick the team.

Heres what i did for the Local script GUI, I'm just learning this for now so not really the best way i could have coded it right now, but it does simulate what i want to happen.

Player.PlayerAdded:Connect(function(player)
    if player.Team == TeamService.Blue then
        Frame.Visible = false
    else
        Frame.Visible = true
    end
end)

Hiders.MouseButton1Click:Connect(function(player)
    
    
    local result = ReplicatedStorage.RemoteFunction:InvokeServer(TeamHiders)
    print(result)
    if result == true then
        Frame.Visible = false
    else
        Frame.Visible = false
    end
end)

Here's what i did for the server script to assign the players a team, I'm sorry I'm still fairly new to roblox so i don't know if my approach is correct im just going with what closely gets me to the output.

game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function (player, Team)
    

    
    if Team == teamService.Blue then
        player.Team = Team
        
        print(ChoosenTeam)
        return "player Team is blue"
    end
    
    if Team == teamService.Red then
        player.Team = Team
        
        print(player.Team)
        return "player Team is red"
    end

end

And here is my script for the Morph, so i got this click detector which should tell the game that whenever its clicked transform the player into whatever form this is scripted on.

local model = script.Parent.Parent
script.Parent.MouseClick:Connect(function(player)
    
    if player.Team == teamservice.Blue then
        
        local oldCharacter = player.Character
        local newCharacter = model:Clone()

        newCharacter.HumanoidRootPart.Anchored = false
        newCharacter:SetPrimaryPartCFrame(oldCharacter.PrimaryPart.CFrame)

        player.Character = newCharacter
        newCharacter.Parent = workspace 
    end 
end)

The players under blue side should only encounter this once since the UI should only appear when they do not have a team or are loaded in the game, but what happens is the blue players whenever they morph into a block they encounter the GUI prompt again.

I was expecting by limiting the player teams to nil it would only show the UI, and if the player has a team already then the UI would not show itself, the same goes to when the player decides to morph the player UI should not be visible.


Solution

  • So turns out i can just turn off spawn on reset.