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

Why does my tool work in play solo but not in game? [RESOLVED] [closed]

Asked by 10 years ago

Update: Turns out I had to make the main script a local script :/

I made a basic weapon and it works in Play Solo, but when I publish the game, it doesn't work.

The weapon has 2 scripts, the main one is a non-local script in the handle.

local Debounce = true
function onEquip(Mouse)
    local Character = script.Parent.Parent.Parent
    local Torso = Character.Torso   
    Mouse.Icon = "rbxasset://textures\\GunCursor.png"
        function onClick(Mouse)
            if Torso then
                if Debounce then
                    Debounce = false
                    Mouse.Icon = "rbxasset://textures\\GunWaitCursor.png"       
                    local Location = Mouse.Hit
                    script.Parent.Fire:Play()
                    x = Instance.new("Part")
                    y = Instance.new("BodyForce")
                    z = script.Parent.Parent.BulletScript:Clone()
                    x.FormFactor = 3        
                    x.Size = Vector3.new(0.2, 0.2, 1.6)
                    x.Name = "Laser"
                    x.BrickColor = BrickColor.new("Really red")
                    x.CFrame = CFrame.new(script.Parent.Position + (script.Parent.CFrame.lookVector * 3),(Mouse.UnitRay.Direction * 1000))
                    x.Velocity = x.CFrame.lookVector * 200      
                    z.Parent = x
                    z.Disabled = false
                    y.force = Vector3.new(0, 12.5, 0)
                    y.Parent = x
                    x.Parent = Workspace
                    wait(1)
                    Debounce = true
                    Mouse.Icon = "rbxasset://textures\\GunCursor.png"
                end
            end
        end
    Mouse.Button1Down:connect(function()onClick(Mouse)end)
end
script.Parent.Parent.Equipped:connect(onEquip)

The other one which is located directly in the tool is also non-local, and is responsible for doing damage.

local x = script.Parent

function onTouch(part)
    local Character = part.Parent:FindFirstChild("Humanoid")
    if Character then
        Character:TakeDamage(25)
        x:Destroy()
    else
        x:Destroy()
    end
end
x.Touched:connect(onTouch)

Sorry if there is an obvious mistake, I am just starting out.

0
Any script that has to deal with the mouse should always be local. MrNicNac 855 — 10y

Locked by TheMyrco

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
1
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

Scripts load at different times when you run them locally vs on the server. In Play Solo, all scripts run locally (because there is no server), so certain things (like PlayerAdded, for example) fire at different times.

adding a short wait to the beginning of the script usually makes these problems go away.

Ad