Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LocalScript not setting values, is this supposed to happen?

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)

2 comments

0

P.S. After I click, line 2 of the script doesn't even fire, it literally just doesn't see the change

0

soo much code to go through

1 answer

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

2 comments

0

Well then how can I use the players mouse to determine where and when to fire a cannonball?

0

Remote Events

This discussion is preserved as it was. New answers, comments, and votes are closed.