I'm getting this error message, "Unable to cast value to Object" when I try to call a Remote Function in a Script. I know I have to use a Local Script, but I can't seem to figure out how to call ".Touched" In a Local Script. It just doesn't work..
Script
local levelsHandler = require(game:GetService("ReplicatedStorage").LevelsHandler)
local circle = script.Parent.Parent.SpawnPad.Circle
local outline = script.Parent.Parent.SpawnPad.Outline
local isTouched = false
local function chooseRandom(dictionary)
local list = {}
for key, value in pairs(dictionary) do
list[#list+1] = {key = key, value = value}
end
if #list == 0 then return end
return list[math.random(#list)]
end
function OnTouch(part)
local humanoid = part.Parent:WaitForChild("Humanoid")
if (humanoid ~= nil) then
if isTouched == false then
isTouched = true
circle.Color = Color3.fromRGB(38, 255, 0)
outline.Color = Color3.fromRGB(38, 255, 0)
local chosen = chooseRandom(levelsHandler)
print("Selected Level: "..chosen.key)
game.ReplicatedStorage.CreateLevel:InvokeClient(chosen.key) -- Error
end
end
end
script.Parent.Touched:Connect(OnTouch)

7 comments
im not trying to be funny trust me im lazy to capitalize
oops too long lol
ok fixed the super long script
I dont have a player parameter in my StarterPlayer>StarterPlayerScripts>LocalScript and that one works fine
Also, I tried this and it didn't work. I'm not getting any error messages though. My Print/Console messages are going through as well. Very Strang...
oh hey you used localscript, then use localplayer, if you are using normal script use that way
what's your new script? can you update it on your question or post another