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

Script keeps spawning in multiple models, how do i fix?

I have a game i'm working on, and i've been trying to spawn in different models, but it always spawns in the amount of players there are.

--localscript
local RemoteEvent = game.ReplicatedStorage.npc1
local Button = script.Parent
local debounce = false
Button.MouseButton1Up:Connect(function()
	if debounce == false then
		debounce = true
		RemoteEvent:FireServer()
		wait(1)
		debounce = false
	end
end)

--globalscript
local debounce = false
local DIST_FROM_PLAYER = 20
local RemoteEvent = game.ReplicatedStorage.npc1

RemoteEvent.OnServerEvent:Connect(function(player)
	character = player.Character
	Mod = game.ServerStorage.NPC1    --Change test to whatever you have named the Model/Item you want to spawn
	clone = Mod:clone()
	clone:SetPrimaryPartCFrame(CFrame.new(character.PrimaryPart.CFrame.Position+(DIST_FROM_PLAYER*character.PrimaryPart.CFrame.LookVector)))
	clone.Parent = workspace.zombies
	wait()
end)

Both the localscript and globalscript are in the gui button. Thank you!

1 answer

Found out, i needed to put the global script into ServerScriptService

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