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

Why doesn't the bullet clone?

Asked by 6 years ago

I do not know why the Bullet doesn't clone please help

Player = game.Players.LocalPlayer Mouse = Player:GetMouse();

script.Parent.Activated:connect(function() game.ServerStorage.Bullet:Clone() game.ServerStorage.Bullet.Parent = workspace game.Workspace.Bullet.CFrame = Mouse.hit end)

0
Please format your code and put it into a code block. RockerCaleb1234 282 — 6y
0
you should define them as variables, like local bullet = game.ServerStorage.Bullet:Clone(). Then set the Parent and CFrame using `bullet`. PyccknnXakep 1225 — 6y
0
can you format it into a code block or put each line of code on a seperate line ninja_eaglegamer 61 — 6y

1 answer

Log in to vote
2
Answered by
DanzLua 2879 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Well I'm taking an educated guess and saying this is a LocalScript because you are getting the LocalPlayer from players. If so you cannot access ServerStorage from a LocalScript. Because of this you'll need to use both a LocalScript and a Script to get this done. First Create a LocalScript, a Script, and a RemoteEvent, ideally in the same Parent so we can get to it easily.

Let's start on the LocalScript, first we create an activated event, guessing that parent is a tool. When this event fires we will fire the remoteevent and send over the mouse hit

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

script.Parent.Activated:connect(function()
    re:FireServer(mouse.Hit)
end)

Now inside the Script we will create the event for the remoteevent and then clone the bullet

local re = script.Parent.RemoteEvent

re.OnServerEvent:connect(function(plr,hit)
    local bullet = game.ServerStorage.Bullet:Clone()
    bullet.Parent=workspace
    bullet.CFrame=hit
end)

Now in your script you had a few problems, but two of them were that you were not assigning the bullet's clone to a variable and that you were setting the bullet instance inside serverstorage aka the original instance's parent instead of the clone, also the same with the cframe Also you don't do mouse.hit, it's mouse.Hit, ;p

Ad

Answer this question