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

Can you aim a tool without a local script?

Asked by
Smunkey 95
8 years ago

I need to aim a tool towards where the player clicks.

I have this script here in local

local tool = script.Parent
local mouse = game.Players.LocalPlayer:GetMouse()

function pew()
    wait (.01)
local arrow = script.Parent.needle
    arrow.CFrame = CFrame.new(tool.Handle.Position, mouse.Hit.p) --like this, where the tool does something in the direction of your mouse click

end
tool.Activated:connect(pew)

There is a script in server which does the rest but i'm certain it works fine, but i'll provide it anyways.

local tool = script.Parent
local bullet = game.ReplicatedStorage.bullets.needle 
local sound = tool.Sound


function pew()
sound:Play()
local arrow = bullet:clone() 
arrow.Parent = tool 
game:GetService("Debris"):AddItem(arrow, .22)
    local v = Instance.new ("BodyVelocity", arrow)
v.velocity = arrow.CFrame.lookVector *90
v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
tool.ManualActivationOnly = true
wait (.3)
tool.ManualActivationOnly = false
end

tool.Activated:connect(pew)

But it only works in studio because of the whole localscript interacting with server objects thing.

Is there a way I could aim the tool using a server script?

I could probably turn off filtering to make it work, but I would like to keep that on since it helps with learning to script good.

0
Consider using RemoteEvents. You could parent the bullet to the character if you wanted. TheDeadlyPanther 2460 — 8y
0
I don't see how remote events will help? I think I clearly stated the problem was I needed to launch the object in the direction of the mouse click. I'll revise my question to make that more clear though for others Smunkey 95 — 8y
0
You could do that, but that's a very bad idea. You never want server to handle such client interactions, or the user experience won't be smooth. ZarsBranchkin 885 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

You shouldn't

All input should be handled locally. Clients expect immediate feedback when they give an input, and in this case they expect the movement of their mouse to be met with a visual feedback of the aiming. If this happens with the server, you're going to be met with lag. And people hate lag.

Just tell the server, but handle it locally.

1
A good wiki article to reference: http://wiki.roblox.com/index.php?title=Fighting_Lag XAXA 1569 — 8y
Ad
Log in to vote
0
Answered by
IcyEvil 260 Moderation Voter
8 years ago

It is possible ***But I would NOT recommend it as it would cause tremendous lag. ***

To fix your problem put the entire script within the tool itself. Aimdown-site would be a different script(just for neatness)

Answer this question