Heres My Attempt
--Control Script local player = script.Parent.Parent script.Parent.Touched:connect(function(hit) local tool = game.Lighting.Slide:Clone() tool.Name = "Control"..hit.Parent.Name tool.Parent = player.Name end)
From what I am reading I think you are using a LocalScript. If so all you need to do is get the local player like so:
local players = game:GetService("Players") player = players.LocalPlayer
Hope this helps and have a great day scripting!
Edit 1: If the script is a descendant of a player then use a LocalScript. Otherwise you will have to get the player either by looping through the players and applying it to each one, or getting the player via an event such as the PlayerAdded or Touched events. Also as the other answers point out, you should us something other than Lighting for storage and :Connect instead of :connect.
game.players.playeradded:connect(Function (plr) end)
plr is now your player.
Script.Parent.Parent can only be used when you insert the script inside a tool in the StarterPack. Since you're using a Touched event, what you can do is
script.Parent.Touched:connect(function(hit) if hit.Parent then local player = game.Players:GetPlayerFromCharacter(hit.Parent) ---now player is defined if player then local tool = game.Lighting.Slide:Clone() tool.Name = "Control"..player.Name tool.Parent = player.Name end end end)
also don't put your script in lighting, i'm just showing you what the script should be like.
Using a thousands of Parent's is bad practicing! You should be using:
script.Parent.Touched:Connect(function(char) local plr = game:GetService("Players"):GetPlayerFromCharacter(char.Parent) end)
Also you're using :connect()
which is deprecated, you should be using :Connect()
. Using a Lighting
as your storage is bad, you should be using ReplicatedStorage
! Here,
Script:
-- Control Script local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Put your tool inside a ReplicatedStorage! script.Parent.Touched:Connect(function(hit) local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) local tool = ReplicatedStorage:WaitForChild("Slide"):Clone() tool.Name = "Control"..hit.Parent.Name tool.Parent = plr.Name -- What are those two lines up here?^ end)
Hope that I helped you!