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

LocalScript not setting values, is this supposed to happen?

Asked by 5 years ago

I have a LocalScript in a tool that is supposed to set a vector3 value in workspace, and a bool value. The LocalScript says that the values changed, and even the explorer properties tab say they've changed, but when printed out with the script that needs them, itsays they haven't changed. LocalScript in Tool:

local Player = game:GetService('Players').LocalPlayer
local Mouse = Player:GetMouse()
local cannon
local cannonNum = 0
local clicked = false
Mouse.Button1Down:Connect(function()
    cannon.clicks.Value = true
    print('clicked')
end)
while cannon == nil do
    cannonNum = cannonNum + 1
    if workspace:FindFirstChild('OmniCannon'..cannonNum) then
        repeat wait() until workspace:FindFirstChild('OmniCannon'..cannonNum).Seat.Occupant
        if workspace:FindFirstChild('OmniCannon'..cannonNum).Seat.Occupant == Player.Character.Humanoid then
            cannon = workspace:FindFirstChild('OmniCannon'..cannonNum)
        end
    else
        break
    end
end
while wait() do
    if cannon then
        cannon.look.Value = Mouse.Hit.p
    end
end

Script in essentially workspace:

local barrel = script.Parent.Parent.barrel1
script.Parent.Parent.clicks.Changed:Connect(function(val)
    print(script.Parent.Parent.look.Value)
    print(script.Parent.Parent.clicks.Value)
    if script.Parent.Parent.clicks.Value == true then
        script.Parent.Parent.clicks.Value = false
        print('unclicked')
        if not script.Parent.Parent:FindFirstChild('Cannonball') then
            local cannonBall = Instance.new('Part')
            cannonBall.Shape = 'Ball'
            cannonBall.BrickColor = BrickColor.new('Black')
            cannonBall.Material = 'Slate'
            cannonBall.Name = 'Cannonball'
            cannonBall.Position = barrel.Position
            cannonBall.Anchored = false
            cannonBall.CanCollide = false
            cannonBall.Size = Vector3.new(1, 1, 1)
            local cannonForce = Instance.new('BodyVelocity')
            cannonForce.Velocity = script.Parent.Parent.look.Value * 100
            cannonForce.Parent = cannonBall
            cannonBall.Parent = script.Parent.Parent

            cannonBall.Touched:Connect(function(hit)
                if hit.Parent.Name ~= 'Cannon' then
                    local explosion = Instance.new('Explosion')
                    explosion.Position = cannonBall.Position
                    explosion.BlastRadius = 5
                    explosion.Parent = cannonBall
                    explosion.Hit:Connect(function(hit)
                        if hit:findFirstChild('qCFrameWeldThingy') then
                            hit:findFirstChild('qCFrameWeldThingy'):Destroy()
                        end
                        cannonForce:Destroy()
                        cannonBall.Anchored = true
                        repeat wait() until not cannonBall:FindFirstChild('Explosion')
                        cannonBall:Destroy()
                    end)
                end
                wait(3)
                if cannonBall then
                    cannonBall:Destroy()
                end
            end)
        end
    end
end)
0
P.S. After I click, line 2 of the script doesn't even fire, it literally just doesn't see the change repgainer3 35 — 5y
0
soo much code to go through DaCrazyDev 444 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

It doesnt work because you can't set a value in workspace by local script you have to use a Server script

It changes local but not Server wide

0
Well then how can I use the players mouse to determine where and when to fire a cannonball? repgainer3 35 — 5y
0
Remote Events Leamir 3138 — 5y
Ad

Answer this question