From what it sounds like, his value is just the string name of the player, not some obj reference. So you’d be trying to manipulate a non-existant .Team property of said string.
Edit: @liuthemoo Hey, I saw you changed your code (presumably after seeing my comment). I just want to let you know that the devforum is a place to learn! Even if you post incorrect code, someone will (hopefully) point it out and future developers reading these threads may learn something from your mistake and from the person correcting you. There’s absolutely nothing wrong with making mistakes!
There’s a better way to do this rather that would shorten it down.
@liuthemoo’s solution WOULD WORK (no idea why you changed it) if you used the alternative.
Instead of assigning the player’s name to a StringValue, you can use an ObjectValue. You would do something along the lines of ObjectValue.Value = game:GetService('Players').Player. When you do this, you would change the Player’s Team by doing Player.Value.Team = newTeam.
You would access the same ObjectValue from that Script. If you store the ObjectValue in, let’s say, ServerStorage, you can access it like you would access any other object: game:GetService("ServerStorage").Object.Value. When you access it like this, you’re essentially looking at the Player. If you were to do .Team following that, you would then have access to the Player’s Team object.
That would return the Team the player is on, assuming that you stored the ObjectValue in ServerStorage and called it Object. If you want to change the Team they’re on, you can just append = game:GetService("Teams"):FindFirstChild("INSERT_TEAM_NAME_HERE") to the end.
Oops, probably should’ve replied to you acknowledging having read your comment. I completely understand that incorrect code is perfectly acceptable, but the last thing I’d want is for a developer to get the idea that Object Values and String Values are the same or something. Thanks for pointing out my error!
Blue.Touched:Connect(function(hit)
if hit.Name == 'Thing' then
print('Touched') -- It prints this and everything else below doesn't happen.
hit.Owner.At.Value.Team = game:GetService('Teams'):FindFirstChild('Blue')
end
end)
Why do you have two Value objects? You should make sure that that the object you’re using is an ObjectValue and not a StringValue and has a value assigned to it. Is there a Team called Blue?
The At is changed by a remote event fired by the player.
local RS = game:GetService(“ReplicatedStorage”)
local Event = RS:WaitForChild(“ChangeOwner”)
Event.OnServerEvent:connect(function(player, Thing)
Thing:SetNetworkOwner(player)
Thing.Owner.At.Value = player
end)
It changes the ‘At’ Value to the player, the only problem is the team not changing.
You’re saying that you’re getting no errors. This issue you’re having should not be happening. Are you sure both your Touched event connection and RemoteEvent (be sure that it’s an Event and not Function) are working? I replicated your code and hierarchy and it works fine for me. The problem you’re having is due to outside interference from either your set up or another script.
P.S: Your code isn’t formatted properly. Please look at this topic I posted to see how you can format it. You’re using block quotes and not code blocks.