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

How I transform a helmet giver from OnTouched(hit) to OnClick(player) ?

Hello, I want make a Helmet giver with a ClickDetector. So I want transform this script(touch) for use with ClickDetector. Thank for your help.

//local player = game.Players.LocalPlayer
//function onClick(player)
//	local character = player.Character
//  if character then


function onTouched(hit)
	if hit.Parent:findFirstChild("Humanoid") ~= nil and hit.Parent:findFirstChild("Helmet") == nil then
		local g = script.Parent.Parent.Helmet:clone()
		g.Parent = hit.Parent
		local C = g:GetChildren()
		for i=1, #C do
			if C[i].className == "UnionOperation" or "Part" then
				local W = Instance.new("Weld")
				W.Part0 = g.HeadPosition
				W.Part1 = C[i]
				local CJ = CFrame.new(g.HeadPosition.Position)
				local C0 = g.HeadPosition.CFrame:inverse()*CJ
				local C1 = C[i].CFrame:inverse()*CJ
				W.C0 = C0
				W.C1 = C1
				W.Parent = g.HeadPosition
				g.HeadPosition.Transparency = 1
			end
				local Y = Instance.new("Weld")
				Y.Part0 = hit.Parent.Head
				Y.Part1 = g.HeadPosition
				Y.C0 = CFrame.new(0, 0, 0)
				Y.Parent = Y.Part0
		end

		local h = g:GetChildren()
		for i = 1, # h do
			h[i].Anchored = false
			h[i].CanCollide = false
		end
		
	end
end

script.Parent.Touched:connect(onTouched)

//script.Parent.ClickDetector.MouseClick:connect(onClick)`

1 answer

Try this!

script.Parent.ClickDetector.MouseClick:Connect(function(CalledBy)
	if CalledBy.Character:FindFirstChild("Helemt") == nil then
		local g = script.Parent.Parent.Helmet:clone()
        g.Parent = CalledBy.Character
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "UnionOperation" or "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.HeadPosition
                W.Part1 = C[i]
                local CJ = CFrame.new(g.HeadPosition.Position)
                local C0 = g.HeadPosition.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.HeadPosition
                g.HeadPosition.Transparency = 1
            end
                local Y = Instance.new("Weld")
                Y.Part0 = CalledBy.Character.Head
                Y.Part1 = g.HeadPosition
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            h[i].Anchored = false
            h[i].CanCollide = false
        end
	end
end)

4 comments

0

You cannot clone a helmet to the localplayer because a player cannot clone things in a localscript you must need a remote event therefore your script is incorrect.

0

@JesseSong, I never said to put it in a LocalScript. Note: Client is able to clone things, but it won't replicate.

0

@JesseSong your grammar trash ---> input clown emoji

0

13:01:15.536 - Workspace..Button.Script:2: Expected identifier when parsing expression, got '02' don't work, and it's helmet not helemt

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