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

How can I fix this script to run when touched?

Asked by
mrcool2 75
9 years ago

This is a script that was made to communicate with a local part and change the local part's properties when touched by a player, however in testing, it does not work and shows this error in the output:

14:04:17.509 - Value is not a valid member of Model

14:04:17.510 - Script 'Workspace.Part.Script', Line 3

14:04:17.510 - Stack End

This is the script that I am using in the block that the player touches:

script.Parent.Touched:connect(function(hit)
    if game.Players:FindFirstChild(hit.Parent.Name) then
        hit.Parent.Value.Value = true
    end
end)

and this is the localscript that I am using to spawn the localpart, and change its properties when the player touches the brick that the script above is in:

local character = game.Players.LocalPlayer.Character
local container = Workspace:FindFirstChild("LocalBin")
if not container then
    container = Instance.new("Camera")
    container.Name = "LocalBin"
    container.Parent = Workspace
end

local platform = Instance.new("Part")
platform.CFrame = platform.CFrame * CFrame.new(23, 3.5, -119.5)
platform.Anchored = true
platform.Size = Vector3.new(2, 7, 7)
platform.LeftSurface = "SmoothNoOutlines"
platform.TopSurface = "SmoothNoOutlines"
platform.Material = "Slate"

local StoneSound = Instance.new("Sound")
StoneSound.Name = "Slateskin"
StoneSound.SoundId = "rbxassetid://270070244"
StoneSound.Volume = 1
StoneSound.Parent = game.Workspace.soundpart
StoneSound.Looped = false
StoneSound.Pitch = 0.8

platform.Parent = container

local p = Instance.new("BoolValue",character)
p.Changed:connect(function()
    game.Workspace.soundpart.Slateskin:Play()
    for i=3.5, -3.8, -0.083 do
        wait(0.01)
        container.Part.CFrame = CFrame.new(23, i, -119.5)
    end
end)

There is nothing wrong with the second script, I am just using it as a reference just so that it may help, the only errors I am getting is from the first script that I mentioned at the beginning

3 answers

Log in to vote
1
Answered by 9 years ago

make sure that the value object is put in the player everytime that there character spawns thats the best advice that i have for you

0
I am sorry but I do not know what you mean by that :c mrcool2 75 — 9y
0
the script is looking for an Object named value within the player and is not finding it and when you try to use it the computer is returning nil or nothing and breaking ProfessorSev 220 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

im sry but i dont know.

Log in to vote
0
Answered by
joalars2 107
9 years ago

What ProfessorSev meant is that you should probably spawn in the bin, parts, sounds, values, EVERY time the player spawns. Heres a function you can use.

game:GetService("Players").PlayerAdded:connect(function(plr)
    plr.CharacterAdded:connect(function(Character)
        --Place the creation of the bin for the local parts, actual parts, sounds, values, here.
        --It will be run every time the player respawns, because local parts are removed upon death.
    end)
end)
0
Messed up the code a bit when i first wrote it, its fixed now tho joalars2 107 — 9y
0
I cannot seem to get this to work :I, I am supposed to be putting this with the local script aren't I? mrcool2 75 — 9y

Answer this question