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

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

Asked by
VVoretex 146
4 years ago

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)
0
What script doesnt work Ai code or movement code? JesseSong 3916 — 4y
0
well the AI code will break when i try to move it from ReplicatedStorage to Workspace VVoretex 146 — 4y
0
So what I assume your trying to do is to move an ai? JesseSong 3916 — 4y
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 VVoretex 146 — 4y
View all comments (4 more)
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. JesseSong 3916 — 4y
0
no it doesnt run inside replicatedstorage VVoretex 146 — 4y
0
it begins running when inside workspace VVoretex 146 — 4y
0
Thats what I said npc cant run in replicated storage because its both client sided and server sided but it works in workspace JesseSong 3916 — 4y

1 answer

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago

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.

Ad

Answer this question