Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't this working..?

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)

1 comment

0

edit 1: fixed noob.Parent = workspace to noob.Parent = game.workspace my bad, n00b mistake

2 answers

✓ Accepted answer

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)

2 comments

0

Thanks! It works now :D

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.

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

5 comments

0

Still won't work for some reason.

0

I honestly don't know then. Sorry.

0

Really, you down voted me? Pathetic.

0

I didn't voted you down? I couldn't have anyway

0

True, my bad.

This discussion is preserved as it was. New answers, comments, and votes are closed.