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)
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.
no u
Yes, me
im useing a normal script a non local script
Also as the other answers point out, you should us something other than lighting for storage and :Connect instead of :connect.
@incapaz what do you mean?
In one of my recent projects I got the player using a remote event, if that helps.
game.players.playeradded:connect(Function (plr)
end)
plr is now your player.
Fail.
Yea, a total fail, it should work, if it doesn't then someone can correct me...
I'll tell you the errors. 1. game.players errors because an object named players isn't inside game. 2. playeradded is not a valid member of Players, 3. connect should be Connect 4. Function should be function 5. there should be no space between function and (plr)
Lel, 5 errors in only 2 lines...
Wow
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!
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
Un, what's a normal script? Also, you shouldn't use Lighting as storage.
can you explain what is going on a little better
I edited my answer for you @basstracker1970
Please properly indent your code as it makes it easy to read and debug.