Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Why won't this script work?
local player = game.Players.LocalPlayer
local clone = game.ReplicatedStorage.Pyro:Clone()
script.Parent.ClickDetector.MouseClick:connect(function()
clone.Parent = player.Backpack
end)
It's in a local script, in a part with a clickdetector.
The name of the tool is correct. |
|
|
Use a normal Script, and paste this into it:
local player = game.Players.LocalPlayer
local clone = game.ReplicatedStorage.Pyro:Clone()
function onClicked(hit)
clone.Parent = game.Players[hit.Name].Backpack
end
script.Parent.ClickDetector.mouseClick:connect(onClicked)
#code web.workspace.Player63541429.Name = "SamTheLollipop" |
|
|
whoops, local player is useless
local clone = game.ReplicatedStorage.Pyro:Clone()
function onClicked(hit)
clone.Parent = game.Players[hit.Name].Backpack
end
script.Parent.ClickDetector.mouseClick:connect(onClicked)
#code web.workspace.Player63541429.Name = "SamTheLollipop" |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Thanks! |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
It only works for the first player to click it, doesn't work if another player clicks after that player.
Any solution for this? |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Bump |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Buuump |
|
|
I dont think you can use localplayer in a normal script.
I made that mistake today.
local doesnt work in a normal script im pretty sure
|
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
I'm not using a normal script, I'm using a local script. I tried @SamTheLollipop's method but it doesn't work. |
|
|
function onClick(click)
for i,v in pairs (game.ReplicatedStorage:GetChildren()) do
if v.ClassName == "Pyro" and not click.Backpack:FindFirstChild(v.Name) and not click.Character:FindFirstChild(v.Name) then
c = v:Clone()
c.Parent = click.Backpack
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
Try that,
|
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
That doesn't seem to work. I used a normal script, was it supposed to be a local? |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Doesn't work in a local script either. |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Bump |
|
Josh_RTGJoin Date: 2012-09-10 Post Count: 59 |
Still need help with this ;( |
|
|
i made some mistakes, lol
function onClick(click) -- The Function , rename if you want.
for i,v in pairs (game.Lighting:GetChildren()) do
if v.ClassName == "Pyro" then -- Already renamed the tool for you
c = v:Clone()
c.Parent = click.Backpack -- Rename "click" if you rename it on line 1
end
end
end
script.Parent.ClickDetector.MouseClick:connect(onClick)
|
|
mrmario04Join Date: 2012-02-04 Post Count: 139 |
Modes local script only do something on ### screen or am I wrong? |
|
mrmario04Join Date: 2012-02-04 Post Count: 139 |
Does, auto correct
|
|
Hazzatr0mJoin Date: 2014-12-13 Post Count: 1069 |
Using a local script isn't very practical due to ROBLOX going towards FilteringEnabled. It's better to use a script as it would only be replicated to the player that the script belongs to.
Anyway, the issue is that you need to replicate the tool every time the player click on the part, not just once.
You should replicate the tool in the function
function onClicked(hit)
local clone = game.ReplicatedStorage.Pyro:Clone()
clone.Parent = game.Players[hit.Name].Backpack
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
Also, mouseClick is deprecated; you should use MouseClick in new projects.
This is my signature. R$0 |
|
Dev_IcyJoin Date: 2014-06-14 Post Count: 208 |
Insert the clone into the function, right now it only creates a single clone, so once that happens, there are no more clones available. |
|