Wednesday, June 22, 2022
HomeGame Developmentlua - ClickDetector for instrument not working when cloned

lua – ClickDetector for instrument not working when cloned


So, I am making an attempt to make a simulator the place you commerce fidgets and stuff and I watched a bunch of issues about instruments and learn how to give them to a participant and issues and for some purpose I could not drop them (I do know that that is fairly irrelevant, I am simply explaining how I received right here), so I attempted to improvise and I made a drop merchandise button which drops the merchandise you might be at the moment holding. I then wished to have the ability to decide up that merchandise however I additionally could not for some purpose, so I as soon as once more tried to make a script that will get a MouseClick occasion from the ClickDetector, however I could not get it to work. Additionally right here is the merchandise giver script (native script):

native instrument = recreation.Workspace.PopIt
native participant = recreation.Gamers.LocalPlayer
native Money = participant.leaderstats.Money

script.Mum or dad.MouseButton1Click:Join(perform()
    if Money.Worth >= 20 then
        Money.Worth = Money.Worth - 20
        instrument:Clone().Mum or dad = participant.Backpack
    finish
finish)

And right here is the drop script (additionally a neighborhood script):

native dropItemsButton = script.Mum or dad
native participant = recreation.Gamers.LocalPlayer
native itemCloned = 0

dropItemsButton.MouseButton1Click:Join(perform()
    native itemToClone = participant.Character:FindFirstChild("PopIt")
    native playerpos = participant.Character.UpperTorso.Place
    if itemToClone then -- Runs provided that we even have an merchandise geared up
        itemCloned = itemToClone:Clone()
        itemToClone:Destroy()
        itemCloned.Deal with.Place = playerpos
        itemCloned.Mum or dad = recreation.Workspace
    finish
finish)

And eventually, right here is the ClickDetector script (common script within the PopIt instrument):

native ClickDetector = script.Mum or dad.ClickDetector
ClickDetector.MaxActivationDistance = 50000

ClickDetector.MouseClick:Join(perform()
    print("hello")
finish)

For some purpose, the ClickDetector script doesn’t run once I clone the instrument to the workspace on the participant’s location, however once I use the unique instrument within the workspace it prints “hello” prefer it’s purported to. I am undecided why it is not working, nevertheless it looks like as soon as I mother or father the instrument to the participant’s backpack it simply breaks and does not work as a result of I attempted simply working a script to clone it within the workspace and it nonetheless works with the unique and the clone. I am going to attempt on the lookout for different movies about this matter however I am simply fairly uncertain what to do.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments