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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)
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. JesseSong 3916 — 4y
0
@JesseSong, I never said to put it in a LocalScript. Note: Client is able to clone things, but it won't replicate. LikeToScript 108 — 4y
0
@JesseSong your grammar trash ---> input clown emoji frostbix 20 — 4y
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 boblegamer10226 -5 — 4y
Ad

Answer this question