Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't this working..?

Asked by 8 years ago

So when you select the tool, and you click, it suppose to spawn a noob where you clicked but ofc it isnt working..

code:

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Spawner = game.StarterPack.Spawner

Mouse.Button1Down:connect(function()
    if Spawner.Equipped == true then
    local noob = game.ReplicatedStorage.Noob:Clone()
    noob.Parent = game.workspace
    noob:MoveTo(Mouse.Hit.p)
else
    print("hi") 
    end
end)

0
edit 1: fixed noob.Parent = workspace to noob.Parent = game.workspace my bad, n00b mistake DeveloperSolo 370 — 8y

2 answers

Log in to vote
1
Answered by
robocu3 30
8 years ago

Equipped is an event, not a property, and you're getting the Spawner in StarterPack, which will never be equipped by the player, as it is replicated into the Backpack object when a new character is created. To do this, a common practice would be to parent the code to the tool, something along the lines of this?

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local noob = game.ReplicatedStorage:WaitForChild("Noob"):Clone()
local spawner = script.Parent

--the activated event fires when left mouse button is down and the tool is equipped
--this eliminates needing to check if it's equipped
spawner.Activated:connect(function()
    local newNoob = noob:Clone()
    newNoob.Parent = workspace
    newNoob:MoveTo(mouse.Hit.p)
end)
0
Thanks! It works now :D DeveloperSolo 370 — 8y
0
No problem. To expand on line 3, I cloned the noob in replicated storage in case another script cleared the storage, so it'd be in memory and be generally failsafe. in case that needed expanding upon. robocu3 30 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Well, everything looks right, but change 'noob.Parent = game.Workspace'. Remember punctuation.

0
Still won't work for some reason. DeveloperSolo 370 — 8y
0
I honestly don't know then. Sorry. RazorRepulsion 0 — 8y
0
Really, you down voted me? Pathetic. RazorRepulsion 0 — 8y
0
I didn't voted you down? I couldn't have anyway DeveloperSolo 370 — 8y
0
True, my bad. RazorRepulsion 0 — 8y

Answer this question