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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

Ad

Answer this question