Scripts Won't Execute Correctly

I am trying to make a game that is similar to Bomberman.

I have made a bomb model, which explodes five seconds after it is placed (I placed the bomb directly in the workspace to make sure that it works). However, when I moved the bomb to ReplicatedStorage and make the players place them instead, all scripts under the bomb model stop working and it won’t explode. Can someone help figure out what’s going on? Thanks so much!


When your making the player place them did you clone the model like this:

local BombClone = game.ReplicatedStorage.Bomb:Clone()

It’s best to do this format instead because at the time of this request the instance in ReplicatedStorage might not have loaded in yet.

local BombClone = game:GetService("ReplicatedStorage"):WaitForChild("Bomb"):Clone()
-- Versues ^Is more safe --
local BombClone = game.ReplicatedStorage.Bomb:Clone()
1 Like

The reason I believe your code is not working is because you have changed the parent property of the script. Make your script so that it is either enabled after put into cloned into workspace or have it so that the script cloning it into workspace does the task of the script inside the Head Part.

Have you tried placing a print? Just to see if it’s firing first. Also, any errors?

Edit: Did you use a local script? If so, you might need to use a remote event in order for the server scripts to work.


Here’s an alternative method.

local seconds = script.Parent.Seconds

while seconds.Value > 0 do -- do not use exactly 0 seconds, due to errors with NumValues, use IntValues
    seconds.Value = seconds.Value - 1

local function explode()
    local explosion ="Explosion") -- do not use the second parameter
    explosion.Position = script.Parent.Position
    explosion.BlastRadius = 10
    explosion.Parent = workspace -- parent after properties set


They aren’t running for two reasons:

  1. Changes made by a client will not be replicated to the server. This means if the player places a bomb, it will not get sent to the server and only the player will see it.
  2. Normal scripts do not run on the client, as they are meant to run on the server. If you want code to run on the client, make it a LocalScript instead of a Script.

To fix the replication issue, make the player handle the input logic and then fire a remote to the server when a player wants to place a bomb. Then, on the server, do the actual bomb creation and exploding logic. Here’s an example:

-- Client (LocalScript)
function onMouseClick(position)

-- Server (Script)
local BombTemplate = game:GetService("ReplicatedStorage"):WaitForChild("Bomb")

PlaceBombRemote.OnServerEvent:Connect(function(player, position)
    -- Not shown: Check that the player is able to actually place the bomb
    ---           (so they can't spam lots of bombs at once)
    local BombClone = BombTemplate:Clone()
    -- Not shown: Place the bomb in Workspace at position

Thank you for helping! I implemented the example above and the bomb exploded!

Right now, however, the bomb always appears in the same position in the game, right next to where the player spawns. I used the exact same code to determine the bomb’s position (back then I did not have a remote event, but bombs always get placed in the right place).

Is there more to the bomb than the head? If you’re only setting the head’s CFrame, the rest of the model will be left behind. Try using Model:SetPrimaryPartCFrame() with a PrimaryPart set to Head or another part in your model.

P.S. No point calling FireServer with position if you’re not using it on the server, btw! Probably just forgot to remove it or sometihng.

1 Like

You seem to be accepting the parameter of position and firing the server with it. However, the problem with that is when you call the function onKeyPressed You aren’t passing the position parameter that it was meant to take and so it would result to nil. I don’t know if that is something intended but it seems out of place. The FireServer(position) Is passing a nil value.

If you are attempting to place the bomb at a certain location you could do

PlaceBombRemote.OnServerEvent:Connect(function(Player, Position)
    local Character = Player.Character and Player.Character 
    if Character then
        local HumanoidRootPart = Character.PrimaryPart or Character:FindFirstChild("HumanoidRootPart")
        local BombClone = BombTemplate:Clone()
        local MovePart = BombClone:WaitForChild("5"):WaitForChild("Head")
        MovePart.CFrame = HumanoidRootPart.CFrame
        return warn("Character not found")

This is assuming that you want the bomb to be placed at the same position as the HumanoidRootPart.

1 Like

Thanks for helping! I incorporated your suggestions and it works well :slight_smile:

A note about why I put a model named “5” under Bombclone: it serves as the “name” of the Bomb and I have a humanoid that displays its name and a script that changes its name to “4”, “3”, “2”, “1” every second. That way the players can tell from the name how long it will take for the bomb to explode.

In case anyone is wondering, here is the final version of the code:

1 Like

Yep, I’m glad I was able to help you. For the future make sure that you make scripts that are versatile and readable so that when you do need to edit something it will be easy to adapt and read. Also, mark it solved so that people can know that the inquiry has a solution.

Two things:

One. Make sure that, once you find a solution, or are given a solution, you click the checkbox of the reply that has said solution, whether that be your own, or another persons. This allows both new player’s with errors sometime similar to you to know where they need to go to find the solution as well as other player’s that intend to help you realise that you no longer need help, as your problem is solved!

Two. Less related but, you might want to, rather than using Humanoids and model names, a BillboardGui as it’s more practical and more customizable, for example, making the text increase in size and changing the colour from green to orange and to red the closer you get to 0.