If The Player Touches A Part, That Player Gets A Trail, I'm Trying To Do It But Nothing Is Happening I Get The Error: ServerScriptService.Trail:2: attempt to index local 'player' (a nil value) Anyone Can Help? Thanks
local player = game.Players.LocalPlayer local char = player.Character game.Workspace.Part.Touched:Connect(function() local trail = game.ServerStorage.Trail:Clone() trail.Parent = char.Head local attachment0 = Instance.new("Attachment", char.Head) attachment0.Name = "TrailAttachment0" local attachment1 = Instance.new("Attachment", char.HumanoidRootPart) attachment1.Name = "TrailAttachment0" trail.Attachment0 = attachment0 trail.Attachment1 = attachment1 end)
The problem here is that your variables for the player and the character reference LocalPlayer. This is something that is specific to LocalScripts. That means that this is specific to the client's side..
What I suspect that you want instead is to make it so that any player this touches this part gets this trail. We can do this from the server side of things (in fact we have to because of the use of ServerStorage).
Here's how you do that. I added only one new part to the code which checks that whatever touched the Part is in fact a player (otherwise we get index errors because things like regular parts won't have Heads).
I also added an argument to the anonymous function you feed into the Touched event. This gives us the part that collided with our workspace.Part.
game.Workspace.Part.Touched:Connect(function(parttouched) local humanoid = parttouched.Parent:FindFirstChild("Humanoid") -- The above is how we check that this a human it's either the Humanoid or nil. if humanoid ~= nil then local char = humanoid.Parent local trail = game.ServerStorage.Trail:Clone() trail.Parent = char.Head local attachment0 = Instance.new("Attachment", char.Head) attachment0.Name = "TrailAttachment0" local attachment1 = Instance.new("Attachment", char.HumanoidRootPart) attachment1.Name = "TrailAttachment0" trail.Attachment0 = attachment0 trail.Attachment1 = attachment1 end end)