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

This AI script won't work when i change the parent, any help?

So, im making an item placement system, and i am moving a model from the replicatedstorage to the workspace, but for some reason, the script stops working.

AI Code:

local firerate = 0.225--in seconds
local damage = 1

wait(1)

--gunfire
if script.Parent.Parent == workspace then
while true do
	wait(firerate)
local a = workspace:WaitForChild("Normal")
script.Gunshot:Play()
a:Remove()
		
end
end

Movement Code:

wait(0.01)
--Variables
local a = game.ReplicatedStorage.MachineGunner


--MainScript
c = game.Workspace.Course.Scenery.Placement1.TowerPlace
c.MouseClick:Connect(function()
game.ReplicatedStorage.MachineGunner.Parent = workspace
local b = game.Workspace.MachineGunner
b:SetPrimaryPartCFrame(CFrame.new(workspace.Course.Scenery.Placementpos1.Position + Vector3.new(0,0,0)))
b.MachineGun.Bipod.Transparency.Transparency = 0
end)

8 comments

0

What script doesnt work Ai code or movement code?

0

well the AI code will break when i try to move it from ReplicatedStorage to Workspace

0

So what I assume your trying to do is to move an ai?

0

well no, I'm trying to get a Defender/Tower and moving it to that specific place(that part works) but then, I try to move it to the workspace, but then the AI wont shoot, yet when if i don't have it in replicatedstorage it works just fine

0

Thats because replicated storage is a storage used to as the name suggests replicate objects client/server sided thats why it doesnt work because npc cant run client sided.

0

no it doesnt run inside replicatedstorage

0

it begins running when inside workspace

0

Thats what I said npc cant run in replicated storage because its both client sided and server sided but it works in workspace

1 answer

✓ Accepted answer

The reason your code didn't work was because it can't run in replicated storage because replicated storage runs both client and server sided so essentially the client side breaks the request from the server replicated storage is used for remote event s,Bindable function etc. So to conclude it don't put things in replicated storage only for things that you want both client and server to interact with.

Also to move AI/NPC use the service pathfinding. It's more efficient.

To learn about Replicated Storage and Pathfinding click the links.

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