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

Script Works in Solo not in Server?

Asked by 8 years ago

It's been a several years since I've last done anything to this script and now playing through online it is not working. That being said, it works in Studio play, so I'm not sure what's up. If there's anything you guys could do, that'd be amazing. Here's the script:

(I'll be honest, the only thing I did was changed the distance)

player = game.Players.LocalPlayer mouse = player:GetMouse()

deb = true mode = true bombs = {}

wait(1) function click(mouse) if mode == true then if deb == true then deb = false dis = (script.Parent.Parent.Parent.Character.Torso.Position - mouse.Hit.p).magnitude if dis < 100000000000000000000000000000000000000000000000000 then Bomb = Instance.new("Part") Bomb.FormFactor = 0 Bomb.Size = Vector3.new(1,1,1) Bomb.Position = mouse.Hit.p Bomb.Anchored = true table.insert(bombs,Bomb) Bomb.Parent = game.Workspace end

deb = true end else for i = 1,#bombs do wait(0.05) E = Instance.new("Explosion") E.BlastRadius = 10 E.Position = bombs[i].Position E.Parent = game.Workspace bombs[i]:remove() end bombs = {} end end

function type(key) if key == "q" then if mode == true then mode = false script.Parent.Name = "Detonate" else mode = true script.Parent.Name = "Bomb" end end end

function equip(m) m.Button1Down:connect(function() click(m) end) m.KeyDown:connect(type) end

script.Parent.Selected:connect(equip)

PS: How can I make is a continuous streams of Bombs while the mouse is clicked down?

0
Please place your script in a code block. Also, is this in a Server Script or Local Script? M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

I see what you did wrong.

When you're playing online, there is a delay between the script running and objects loading. When running in Studio, there is less of a delay because everything is happening locally on your hardware. The problem is that you need to wait until everything exists. I would recommend using :WaitForChild() for this.

Example:

script.Parent.Parent.Parent.Character.Torso.Position

should look more like this

repeat wait() until script.Parent.Parent.Parent.Character
local char = script.Parent.Parent.Parent.Character
local torso = char:WaitForChild("Torso")

You need to wait until these objects exist. Otherwise the script will run and these objects won't exist yet, breaking your script.

I hope this helped you.

Ad

Answer this question