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

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

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.

2 comments

0

I'd like to know if its FE or Non-fe or Experimental Mode on

0

Non-FE

1 answer

✓ Accepted answer

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)

2 comments

0

So what steps should be done to make this script work?

0

Use LocalPlayer:GetMouse() for Mouse instead of the Mouse you get from Equipped Event.

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