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

Why does my tool work in Roblox Studio but no online??

Asked by 6 years ago
Edited 6 years ago

So I tried making my script so that when u click, tap, etc it will launch a fireball but this only works on roblox studio and not online. Idk why. THIS IS IN A SCRIPT. Pls Help! <3

My code

local tool = script.Parent
local handle = tool:WaitForChild("Handle")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local head = char:WaitForChild("Head")
local ammo = 1

tool.Activated:Connect(function()


    if ammo == 1 then 
        ammo = 0

        local fireballclone = game.ServerStorage.BallEx:Clone()
            fireballclone.Parent = game.Workspace
            fireballclone.Position = head.Position + (head.CFrame.lookVector * 8)

    local v = Instance.new("BodyVelocity")
            v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
            v.Velocity = player.Character.UpperTorso.CFrame.lookVector * 80 
            v.Parent = fireballclone

    wait(3)
        ammo = 1
    end 
end)

2 answers

Log in to vote
0
Answered by 6 years ago

The script used is a local script. If the game is filtering enabled, then the local script would not be able to access server-sided services such as ServerStorage.

Use ReplicatedStorage instead.

0
thank you so much it worked :D iizWishzii 21 — 6y
0
You are most welcome. Please accept my answer. User#18043 95 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

So if this is in a script, then you can't use LocalPlayer. This is a common mistake and its usually easily fixable. What you could do is put the script inside the tool and use .Parent to find the player.

This should work:

player = script.Parent.Parent.Parent

You will more than likely need to set Disabled = false if your moving the script or have it detect when its parent changes using:

script.Parent.AncestryChanged:Connect(function(c,p)
--do stuff
end)

Answer this question