✓ Accepted answer
The main problem in your script is that you're changing the textbox that is located inside of StarterGui. Children of this object get cloned into a Player's PlayerGui when their character spawns. So you won't be changing the gui of the player who touched the part. To fix this we get the player from the part that touched the part that the event is connected to.
local part = script.Parent
part.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(hit.Parent) then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.ScreenGui.TextBox.Text="Welcome to this game ".. player.Name .. " !"
end
end)
when the player touches the part, we check if first its parent has a humanoid, and then if there is a player associated with that model, if so then we can change the proper textbox.
It's important to remember that if this script is inside a server script it will not work with FilteringEnabled turned on. For that you'll have to use RemoteEvents
2 comments
also, I don't think you can use a property as a variable
You can.