My local script is taking over things

So… My local script in starterplayerscripts is literally not letting ANY other scripts work. or it might not be the local script. So I made a thing so if you touch a part, you do a animation and u become the “infected” team. Just like transfurmation right… So I’m trying to make it so if you die, or touch a certain block, you become the Humans team. but my local script isn’t allowing that…

Note: there are literally NO errors…

My local script:

local Folder = workspace.Infectors -- Change to your folder 
local Animation = game.Workspace.Animation
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

for Index, Part in pairs(Folder:GetChildren()) do
	Part.Touched:Connect(function(touched)
		if touched.Parent:FindFirstChild("Humanoid") then
			local AnimPlay = touched.Parent.Humanoid:LoadAnimation(Animation)
			touched.Parent.HumanoidRootPart.Anchored = true
			AnimPlay:Play()
			AnimPlay.Stopped:wait() --Waits until it finished playing
			touched.Parent.HumanoidRootPart.Anchored = false
			player.TeamColor = BrickColor.new("Really red")
			if player.TeamColor == BrickColor.new("Really red") then
				script.Disabled = true
				if player.TeamColor == BrickColor.new("White") then
					script.Disabled = false
				end				
			end			
		end		
	end)	
end

The touch block to become Human Team script:

local team = BrickColor.new("White")
local part = script.Parent

part.Touched:connect(function(hit)
	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
	if plr then
		plr.TeamColor = team
	end
end)

Is the Human Team script a local or server script?

You can’t change a players team on the client. You need to do it on the server by utilising remote events and sending whatever data you need to the server.

sever script, inside the part.

so what do I do then.
Steps pls?

You should honestly just make everything server sided using a script. I don’t see why you need a local script at all. You can get the player from the hit part and basically do whatever you did in the local script.

Also, I see a huge issue happening here with your local script. So basically, when the .Touched connection runs, it will affect the Local Player, not the “touched” connection. I would rather do all of this from one server script

the reason im using a local script is because I can’t redo this using a normal script, if I were to then I would need insane amount of help.

What would be hard about it? Is there something messing up whenever you tried to make it server sided?

no it’s just idk how to do it using server sided

local Folder = workspace.Infectors
local cache = {}

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function()
        cache[plr] = false
    end)
end)

for _, part in pairs(Folder:GetChildren()) do
    part.Touched:Connect(function(hit)
        local char = hit:FindFirstAncestorOfClass("Model")
        local hum, humpart = char.Humanoid, char.HumanoidRootPart
        local plr = game.Players:GetPlayerFromCharacter(char)
        
        if part.Name == "InfectedTeam" then --change this for infected team
            if not cache[plr] then
                cache[plr] = true

                if hum:FindFirstChildOfClass("Animator") ~= nil then
                    hum.Animator:Destroy()
                end

                humpart.Anchored = true

                local animator, anim = Instance.New("Animator", hum), Instance.new("Animation")
                anim.AnimationId = --PUT ID HERE
                anim.Priority = Enum.AnimationPriority.Action
                anim:Play()
                anim.Stopped:Wait()
                anim.Priority = Enum.AnimationPriority.Core
                
                humpart.Anchored = false
                plr.TeamColor = BrickColor.new("Really red")
            end
        elseif part.Name == "HumanTeam" then --change this for human team
            plr.TeamColor = BrickColor.new("White")
            cache[plr] = false
        end
    end)
end

Try something like this. Put all of the team parts in the same folder, and name them to “HumanTeam” or “InfectedTeam”. Change the stuff that I outlined in the script to match the information that I did not have. If it doesn’t work, let me know

FYI This is all a server script, it doesn’t matter if you put it in workspace or serverscriptservice

wdym team parts? I’m just using the team folder thingy.

I mean the parts that change their team color when touched

bruh ur making this so confusing… but ill try…

It’s not, I’m just organizing it all into one script. I took the two you made and combined it into one. Something like this works better in a server script, and since this one requires a debounce, I used a “local debounce” in a cache table

btw I updated it

Okay I’m finna test this. real quick…

image ?

You have created a variable named team and assigned it to a BrickColor rather than a Team, you need to replace the line with a proper definition.

could u edit my script it do that, I don’t rlly understand sorry.:frowning:

The issue
You are trying to set the player’s team to a color, a color is not a team.
A team object is a team, hence the issue occurs.

The solution:
You’ll have to solve the issue by creating a team object in the Teams service and assigning the variable to it. I don’t know if there’s a better way to explain it sorry.

1 Like