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

This script works if its in workspace, but not if its in a model? [SOLVED]

workspace.Model.Humanoid.Died:connect(function()
	for i=1, 10 do
			local pickup = game.ReplicatedStorage.Xpbrick:Clone()
		local num = math.random(1, 3)
		local num2 = math.random(1, 2)
		pickup.Parent = workspace
		pickup.Position = workspace.Model.Head.Position
		pickup.Velocity = Vector3.new(math.random(-50, 50), -50, math.random(-50, 50))
		if num == 1 then
			pickup.BillboardGui.ImageLabel.ImageColor3 = Color3.new(1, 1, 1) -- fuel
		elseif num == 2 then
			pickup.BillboardGui.ImageLabel.ImageColor3 = Color3.new(0, 0, 1) -- hp
		elseif num == 3 then
			pickup.BillboardGui.ImageLabel.ImageColor3 = Color3.new(0, 0.55, 1) -- ammo
		end
			local light = Instance.new('PointLight', pickup)
		light.Color = pickup.BillboardGui.ImageLabel.ImageColor3
		if num2 == 1 then
			pickup.BillboardGui.ImageLabel.Rotation = 0
		else
			pickup.BillboardGui.ImageLabel.Rotation = 180
		end
		pickup:BreakJoints()
		pickup.Touched:connect(function(hit)
			print'dood'
			if hit.Parent and hit.Parent:FindFirstChild('Humanoid') then
				if num == 2 and hit.Parent.Humanoid.Health < hit.Parent.Humanoid.MaxHealth then -- hp
					hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health + 1.5
					pickup:Destroy()
				elseif num == 1 and hit.Parent.Humanoid.Fuel.Value < 100 then -- fuel
					hit.Parent.Humanoid.Fuel.Value = hit.Parent.Humanoid.Fuel.Value + 4
					pickup:Destroy()
				elseif num == 3 and hit.Parent.Humanoid.bullets.Value < hit.Parent.Humanoid.maxbullets.Value then -- ammo
					hit.Parent.Humanoid.bullets.Value = hit.Parent.Humanoid.bullets.Value + 1
					pickup:Destroy()
				end
			end
		end)
	end
	workspace.Model:Destroy()
end)

SOLVE EDIT: destroying the model destroyed the script which is why the function didnt respond

If I move this script into the model that's this is referring too, it works the same, except one thing...

The Touched function doesn't respond at all if i touch any of the pickups (doesn't print either), anyone got any idea why its not responding?

1 answer

try making a local script then placing it in the workspace

7 comments

2

Refer to "In order for a LocalScript to function."

2

Localscripts cannot function in Workspace.

0

local scripts work in workspace for me doe...

0

No, they don't.

0

They do, I ain't gonna argue with you guys, I know it does for me, And you can't decide what I see.

0

It works in studio because studio is run in offline mode, and in offline mode the client and server is merged.

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