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

How to make a script that puts a name inside the Owner value when touched?

Asked by 4 years ago

Hi. Basically I have a part which is spawned from Lighting.

Inside the part in Lighting, it has a StringValue called Owner.

How would I make it so that when the part is touched, it changed the Owner value to a name?

This is the script inside the part:

de = false

function OnClick(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) and de == false then
        de = true
        local a = game.Lighting.Storage.Dew:clone()
        a.Owner.Value = hit.Parent
        print (hit.Parent)
    end
    wait(2)
    de = false
end

script.Parent.ClickDetector.MouseClick:connect(OnClick)
script.Parent.Touched:connect(OnClick)

The item also has a ClickDetector. Weirdly, it detects me in the print command, but doesn't put my name in the Owner value..

2 answers

Log in to vote
0
Answered by 4 years ago

It is because you wanna get the Name property, as it is a string, whilst the player itself is an Instance. Here is how your script will look like:

local de = false

function OnClick(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) and de == false then
        de = true
        local a = game.Lighting.Storage.Dew:clone()
        a.Owner.Value = hit.Parent.Name -- references the name
        print (hit.Parent)
    end
    wait(2)
    de = false
end

script.Parent.ClickDetector.MouseClick:Connect(OnClick)
script.Parent.Touched:Connect(OnClick)

Also not sure why you put things inside Lightning, I mean, that's why ServerStorage and ReplicatedStorage exists.

0
Hi. No luck sadly.. Nath390Fish 19 — 4y
0
It doesnt seem to want to change the Owner string. Nath390Fish 19 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

bump.

Answer this question