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

My tool in my game will not spawn parts?

I'm currently making a game, where you have to spawn stuff like parts that explode to fight off goblins and such, but when I try to use my tool that spawns a part, which then explodes, it doesn't spawn it..

Here's my tool:

CreatePart - Normal Script:

local tool = script.Parent
local clickEvent = tool.ClickEvent
local partEvent = tool.PartEvent
local clickEventConnection
local partEventConnection
local screenGui = Instance.new("ScreenGui")
local spawnSound = script.Parent.Handle.PartSpawn
screenGui.Parent = game.StarterGui

local waitTime = 0.3

local function createPart(location)
	spawnSound:Play()
	local part = Instance.new("Part")
	part.Size = Vector3.new(2, 1, 2)
	part.CFrame = location
	part.Parent = workspace
	partEvent:FireServer(part)
end

local function onClick(player, clickLocation)
	print("Clicked, and created")
	createPart(clickLocation)
end

local function onEquip()
	print('Equipped')
	clickEventConnection = clickEvent.OnServerEvent:Connect(onClick)
end

local function onUnequip()
	print("Unequipped")
	clickEventConnection:disconnect()
end

tool.Equipped:Connect(onEquip)
tool.Unequipped:Connect(onUnequip)

PartScript - Normal Script:

math.randomseed(tick())
local partConnection
local tool = script.Parent
local partEvent = tool.PartEvent
local function changePart(player, part) 
		part.BrickColor =  BrickColor.Random()
		wait(5)
		part:Destroy()
end

while true do
	partConnection = partEvent.OnServerEvent:Connect(changePart)
	wait(0.1)
end

FireEvent - LocalScript:

local tool = script.Parent
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local clickEvent = tool.ClickEvent
local mana = game.Players.LocalPlayer:WaitForChild("Mana Amount")
local isWait = false
local waitTime = 0.3

local function onActivate() 
	print('worked')
	if mana.Value >= 5 and isWait == false then
		mana.Value = mana.Value - script.Parent.ManaUse.Value
		local clickLocation = mouse.Hit
		clickEvent:FireServer(clickLocation)
	end
end

tool.Activated:Connect(onActivate)

I also have 2 remote events, PartEvent, and ClickEvent.

Everything works except the part spawning. It will take my mana, make a sound and such, but it just wont spawn a part.

Thanks in advance!

1 comment

0

Try printing in-between calling functions and see if they even run.

1 answer

I actually created these scripts, events and values. It works just fine. You must have made a logical error that you didn't show us. Otherwise, it's a probably a lack of :waitForChild() usage in your scripts. Check the output.

By the way, you used partEvent as a RemoteEvent between two server scripts which is not good. It might work in testing but in a filtering enabled server, it's not allowed. As a rule of thumb, you only use RemoteEvents to communicate between server and client. To communicate between scripts on the same scope, you still use a BindableEvent.

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