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

Tool Giver script works fine but tool doesn't work when given to the player?

So basically i'm making mini-things to challenge myself and see how well i'm doing in scripting but i've hit a roadblock and can't figure out how to fix it myself. The "give tool" part works fine but when the player gets the tool the tool doesn't work.. it just breaks.

Tool Giver script {textbutton inside frame inside screengui}:

db = false

script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		db = true
		local tool = game.ReplicatedStorage.Tools.RemoteMine
		local player = game.Players.LocalPlayer
		tool.Parent = player.Backpack
		wait(5)
		db = false
	end
end)

Tool "BombBlink" script:

local Mesh = script.Parent.Mesh
local blink = false

while true do

	blink = not blink
	if blink then
		Mesh.TextureId = "http://www.roblox.com/asset/?id=28512114"
	else
		Mesh.TextureId = "http://www.roblox.com/asset/?id=33378623"
	end
	wait(2)

end

Tool "PlantBomb" script:

Tool = script.Parent
local planting = true
local bomb = nil

local sound = Instance.new("Sound")
sound.SoundId = "http://www.roblox.com/asset/?id=28517063"
sound.Looped = true

local explosion = Instance.new("Sound")
explosion.SoundId = "http://www.roblox.com/asset/?id=28518734"
explosion.Volume = 0.01
explosion:Play()
explosion.Volume = 0.5

function plant(pos)
	
	Tool.Handle.Plant:Play()
   
	local vCharacter = Tool.Parent
	local vHumanoid = vCharacter:FindFirstChild'Humanoid'
	if not vHumanoid or vHumanoid:IsA'Humanoid'==false or vHumanoid.Health<=0 then return end
	local vPlayer = game.Players:playerFromCharacter(vCharacter)

	local spawnPos = vCharacter.PrimaryPart.Position

	bomb = Instance.new("Part")
	bomb.Locked = true
	bomb.formFactor = 2
	bomb.Size = Vector3.new(1,0.4,1)
	bomb.Name = "Mine"
	bomb.Position = pos

	sound.Parent = bomb
	sound:Play()

	explosion:Stop()

	local mesh = Instance.new("SpecialMesh")
	mesh.MeshId = "http://www.roblox.com/asset/?id=28511843"
	mesh.TextureId = "http://www.roblox.com/asset/?id=28512114"
	mesh.Parent = bomb

	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = vPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = bomb

	local script = Tool.BombBlink:clone()
	script.Parent = bomb
	script.Disabled = false

	bomb.Parent = game.Workspace
	bomb.Touched:connect(function(part)
		if part ~= Tool.Handle and part.Parent:FindFirstChild("Humanoid") == nil then
			bomb.Anchored = true
			bomb.CanCollide = false
		end
	end)

	game:GetService'Debris':AddItem(bomb, 60)
end

function blowUp()
	local vCharacter = Tool.Parent
	local vHumanoid = vCharacter:FindFirstChild'Humanoid'
	if not vHumanoid or vHumanoid:IsA'Humanoid'==false or vHumanoid.Health<=0 then return end

	local e = Instance.new("Explosion")
	e.BlastPressure = 12000
	e.BlastRadius = 12
	e.Parent = game.Workspace
	e.Position = bomb.Position
	sound:Stop()
	explosion.Parent = e
	explosion:Play()
	bomb:remove()
	
	bomb = nil
end


Tool.Enabled = true
function onActivated()

	if not Tool.Enabled then
		return
	end

	Tool.Enabled = false

	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
		print("Humanoid not found")
		return 
	end

	local targetPos = humanoid.TargetPoint
	planting = bomb==nil or bomb~=nil and bomb.Parent==nil

	if planting then
		plant(Tool.Handle.Position)
	else
		blowUp()
	end

	Tool.Enabled = true
end


script.Parent.Activated:connect(onActivated)

If you can let me know what the problem is that'd be awesome, once again thanks if you just take your time to read my problem!

2 comments

0

Does the tool have any code? If so then you should show it.

0

There. I added all the scripts the tool has!

1 answer

✓ Accepted answer

You cannot give tools on the client. You should use Remote Events to tell the server to give the player a tool.

2 comments

0

Ok, I will learn how to use events

0

Thank you a lot, I learnt how to use events in about 10 minutes or so and using remote events helped. Thanks for reminding/suggesting using remote events!

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