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

Why is my Model Placer script working only in ROBLOX Studio and not in game?

Asked by 5 years ago

I am currently wondering why is a LocalScript working perfectly in Studio, but does nothing in the game itself.

The LocalScript itself:

lp = script.Parent
local debounce = false

function onButton1Down(mouse)

if not debounce then
    debounce = true
    local grenade = game.ServerStorage:WaitForChild("Grenade")
    local model = grenade:clone()
    model.Parent = game.Workspace
    model = game.Workspace:WaitForChild("Grenade")
    model.PrimaryPart = model.Union
    model:MakeJoints()
    model:MoveTo(mouse.hit.p)
    local cframe = model.PrimaryPart.CFrame
    model:SetPrimaryPartCFrame(cframe * CFrame.fromEulerAnglesXYZ(math.random(0,359), math.random(0,359), math.random(0,359)))
    wait(5)
    debounce = false
    end
end

function onEquipped(mouse)
    mouse.Button1Down:connect(function() onButton1Down(mouse) end)
end

lp.Equipped:connect(onEquipped)

The Script is in a Tool and it is supposed to clone a Model called Grenade from ServerStorage to Workspace where the mouse cursor is.

It works without any problems in ROBLOX Studio. However, when I join the game and use the Tool, it does nothing when I click.

As you can see, it is a LocalScript and there is WaitForChild here. It still works perfectly in ROBLOX Studio, but not in the game.

I kindly request your help and advice, fellow scripters.

Thanks.

0
I'd like to know if its FE or Non-fe or Experimental Mode on Omega_bs 40 — 5y
0
Non-FE MatiWielun 35 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It being Fe or Non-FE aside i have made a Non-FE Demo that can be Edited and Researched thru

So what i've done is Placed the Grenade Model into game:GetService("ReplicatedStorage")

I don't know why it worked that time but its probably because i didn't mind to change it

And since its a Local Script we can indeed use :GetMouse()

local Player_Variable_Name_Here = game:GetService("Players").LocalPlayer:GetMouse() to be Exact

and Use Mouse.Button1Down:connect(function() end) instead

The game works online and in studio probably because its non-fe but heres the Tools API and help for making a FE game with Tools

Tool API

Test Game (Open Source)

0
So what steps should be done to make this script work? MatiWielun 35 — 5y
0
Use LocalPlayer:GetMouse() for Mouse instead of the Mouse you get from Equipped Event. Omega_bs 40 — 5y
Ad

Answer this question